Must JDBC Resultsets and Statements be closed separately although the Connection is closed afterwards?
Posted
by
Mulmoth
on Stack Overflow
See other posts from Stack Overflow
or by Mulmoth
Published on 2010-12-22T08:36:13Z
Indexed on
2010/12/22
8:54 UTC
Read the original article
Hit count: 214
It is said to be a good habit to close all JDBC resources after usage. But if I have the following code, is it necessary to close the Resultset and the Statement?
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = // Retrieve connection
stmt = conn.prepareStatement(// Some SQL);
rs = stmt.executeQuery();
} catch {
// Error Handling
} finally {
try { if (rs != null) rs.close(); } catch (Exception e) {};
try { if (stmt != null) stmt.close(); } catch (Exception e) {};
try { if (conn != null) conn.close(); } catch (Exception e) {};
}
The question is if the closing of the connection does the job or if it leaves some resources in use.
© Stack Overflow or respective owner