According to doc of http://docs.oracle.com/javase/7/docs/api/java/sql/Statement.html#close() ,
When a Statement object is closed, its current ResultSet object, if one exists, is also closed.
But accoring to Must JDBC Resultsets and Statements be closed separately although the Connection is closed afterwards? , it is seems to be a good practice to explicitly close Connection
Statement
and ResultSet
.
If we still need to close ResultSet
, we may need to have a nested try-with-resources statement since we may probably set parameter for Statement
like this:
try (Connection conn = connectionProvider.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql) {//resources of conn and pst
setPrepareStatementParameter(pstmt, kvs);//need to set parameters, so I have to put ResultSet into another try-with-resources statement
try (ResultSet res = pstmt.executeQuery()) {
..............
}
}
Question:
Does put the ResultSet into a separate try-with-resources statement worth anything since the doc states that closing Statement
will close the ResultSet