New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
closing PreparedStatement does not close ResultSet [JDBC634] #664
Comments
Modified by: Martin Sulak (martinsulak)description: When PreparedStatement is declared in try with resources and its ResultSet is not explicitly closed, transaction number freeze, indicating resource leak illustration : int getRow ( Connection connection, int b ) throws SQLException { => When PreparedStatement is declared in try with resources and its ResultSet is not explicitly closed, transaction number freeze, indicating resource leak illustration : int getRow ( Connection connection, int b ) throws SQLException { AutoCloseable interface on PreparedStatement works fine in JayBird 2.2.3. |
Modified by: Martin Sulak (martinsulak)description: When PreparedStatement is declared in try with resources and its ResultSet is not explicitly closed, transaction number freeze, indicating resource leak illustration : int getRow ( Connection connection, int b ) throws SQLException { AutoCloseable interface on PreparedStatement works fine in JayBird 2.2.3. => Closing PreparedStatement either explicitly by close method or by using AutoCloseable interface probably does not close underlying ResultSet. illustration : int getRow ( Connection connection, int b ) throws SQLException { or: int getRow ( Connection connection, int b ) throws SQLException { summary: autoclosing PreparedStatement does not close ResultSet => closing PreparedStatement does not close ResultSet |
Modified by: Martin Sulak (martinsulak)description: Closing PreparedStatement either explicitly by close method or by using AutoCloseable interface probably does not close underlying ResultSet. illustration : int getRow ( Connection connection, int b ) throws SQLException { or: int getRow ( Connection connection, int b ) throws SQLException { => Closing PreparedStatement either explicitly by close method or by using AutoCloseable interface probably does not close underlying ResultSet. illustration : int getRow ( Connection connection, int b ) throws SQLException { or: int getRow ( Connection connection, int b ) throws SQLException { |
Modified by: Martin Sulak (martinsulak)description: Closing PreparedStatement either explicitly by close method or by using AutoCloseable interface probably does not close underlying ResultSet. illustration : int getRow ( Connection connection, int b ) throws SQLException { or: int getRow ( Connection connection, int b ) throws SQLException { => Closing PreparedStatement either explicitly by close method or by using AutoCloseable interface probably does not close underlying ResultSet. illustration : int getRow ( Connection connection, int b ) throws SQLException { or: int getRow ( Connection connection, int b ) throws SQLException { |
Commented by: @mrotteveel I can't reproduce this. Please provide a minimal, complete and verifiable example. Especially show how you verify the transaction count, and how you create the connection. For example, the following code will show that transactions are ended properly, and that the result set is closed:
(where getConnectionViaDriverManager() uses DriverManager.getConnection(String, Properties)) This prints - as expected: Oldest: 1 Enabling debug logging also shows that the transaction is committed as expected. |
Commented by: Martin Sulak (martinsulak) Hello, |
Commented by: @mrotteveel You can add a Java source file as an attachment. And the minimal example should contain everything I need to run, and verify things (either as a set of instructions, or as part of the Java program). However, if you currently use gstat -h to check the values, I would recommend that you also try what I do in printTransactionInfo(Connection), IIRC the statistics in the database header page are not always updated immediately, so can lag behind. |
Submitted by: Martin Sulak (martinsulak)
Closing PreparedStatement either explicitly by close method or by using AutoCloseable interface probably does not close underlying ResultSet.
If ResultSet is not explicitly closed, transaction number freeze, indicating resource leak
It worked fine with JayBird 2.2.3.
illustration :
int getRow ( Connection connection, int b ) throws SQLException {
try (PreparedStatement ps = connection.prepareStatement("select A from MYTAB where B=?")) {
ps.setInt(1, b);
ResultSet rs = ps.executeQuery();
rs.next();
// rs.close(); is required here or transaction counter stops but rs should be closed automatically when execution leaves try block
return rs.getInt(1);
}
}
or:
int getRow ( Connection connection, int b ) throws SQLException {
PreparedStatement ps = connection.prepareStatement("select A from MYTAB where B=?")) {
ps.setInt(1, b);
ResultSet rs = ps.executeQuery();
rs.next();
int val = rs.getInt(1);
// rs.close(); is required here or transaction counter stops but rs should be closed in ps.close
ps.close();
return val;
}
The text was updated successfully, but these errors were encountered: