JDBC introduced a method called closeOnAutoCompletion, which states that it closes the statement, when all dependent resultSets are close.
I have a method to create prepared statements
public final PreparedStatement statement(Connection connection) throws SQLException {
PreparedStatement stmt = connection.prepareStatement(query, ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
stmt.closeOnCompletion();
return stmt;
}
No I'm calling this method as follows
@Test
public void testCloseOnCompletionSemiManually() throws SQLException {
PreparedStatement stmt = shards.statement(db);
assertTrue("Statement must be closeOnAutoCompletion", stmt.isCloseOnCompletion());
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
//System.out.println("Shard id: " + rs.getInt("SHARD_ID"));
}
}
assertTrue("Statement must be closed after all results sets have been processed", stmt.isClosed());
}
The last check fails as the statement is not closed.
Is this a problem due to the mysql implementation? Or did I missunderstand the JavaDoc.
Update: I'm using version 5.1.24
thanks, Muki