Bug #68916 closeOnCompletion doesn't work
Submitted: 10 Apr 2013 11:04 Modified: 21 Nov 2013 16:31
Reporter: Nepomuk Seiler Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:5.1.24 OS:Any
Assigned to: Jess Balint CPU Architecture:Any
Tags: closeOnCompletion, java7, jdbc

[10 Apr 2013 11:04] Nepomuk Seiler
Description:
The method call _closeOnCompletion_ seems to have no effect. I posted a question of stackoverflow [1].

The corresponding code at

StatementImpl.class Line 3041

My IDE couldn't find any usages of the _isCloseOnCompletion_ method or the private field.

cheers,
Muki

[1] http://stackoverflow.com/questions/15923135/mysql-jdbc-closeoncompletion-has-no-effect-on-...

How to repeat:
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());
}
[19 Apr 2013 7:52] Alexander Soklakov
Hi Nepomuk,

Thanks for your report.

JDBC spec describes functionality of this method as:

"Specifies that this Statement will be closed when all its dependent result sets are closed. If execution of the Statement does not produce any result sets, this method has no effect.

Note: Multiple calls to closeOnCompletion do not toggle the effect on this Statement. However, a call to closeOnCompletion does effect both the subsequent execution of statements, and statements that currently have open, dependent, result sets."

It isn't implemented in Connector/J. So verified as described.
[21 Nov 2013 16:31] Daniel So
Added the following entry to the Connector/J 5.1.28 changelog:

"The method Statement.closeOnCompletion() was not working."