Skip to content

Commit b180467

Browse files
Stephen Boeschrxin
authored andcommitted
SPARK-2869 - Fix tiny bug in JdbcRdd for closing jdbc connection
I inquired on dev mailing list about the motivation for checking the jdbc statement instead of the connection in the close() logic of JdbcRDD. Ted Yu believes there essentially is none- it is a simple cut and paste issue. So here is the tiny fix to patch it. Author: Stephen Boesch <javadba> Author: Stephen Boesch <[email protected]> Closes #1792 from javadba/closejdbc and squashes the following commits: 363be4f [Stephen Boesch] SPARK-2869 - Fix tiny bug in JdbcRdd for closing jdbc connection (reformat with braces) 6518d36 [Stephen Boesch] SPARK-2689 Fix tiny bug in JdbcRdd for closing jdbc connection 3fb23ed [Stephen Boesch] SPARK-2689 Fix potential leak of connection/PreparedStatement in case of error in JdbcRDD 095b2c9 [Stephen Boesch] Fix tiny bug (likely copy and paste error) in closing jdbc connection (cherry picked from commit 2643e66) Signed-off-by: Reynold Xin <[email protected]>
1 parent d415f88 commit b180467

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

core/src/main/scala/org/apache/spark/rdd/JdbcRDD.scala

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,23 @@ class JdbcRDD[T: ClassTag](
9696

9797
override def close() {
9898
try {
99-
if (null != rs && ! rs.isClosed()) rs.close()
99+
if (null != rs && ! rs.isClosed()) {
100+
rs.close()
101+
}
100102
} catch {
101103
case e: Exception => logWarning("Exception closing resultset", e)
102104
}
103105
try {
104-
if (null != stmt && ! stmt.isClosed()) stmt.close()
106+
if (null != stmt && ! stmt.isClosed()) {
107+
stmt.close()
108+
}
105109
} catch {
106110
case e: Exception => logWarning("Exception closing statement", e)
107111
}
108112
try {
109-
if (null != conn && ! stmt.isClosed()) conn.close()
113+
if (null != conn && ! conn.isClosed()) {
114+
conn.close()
115+
}
110116
logInfo("closed connection")
111117
} catch {
112118
case e: Exception => logWarning("Exception closing connection", e)
@@ -120,3 +126,4 @@ object JdbcRDD {
120126
Array.tabulate[Object](rs.getMetaData.getColumnCount)(i => rs.getObject(i + 1))
121127
}
122128
}
129+

0 commit comments

Comments
 (0)