closeOnCompletion

Lance Andersen lance.andersen at oracle.com
Wed Feb 17 17:52:52 UTC 2021


I will have to go dig back through my email archive as this was first discussed in 2009.


The overall intent was to deal with code similar to:

----------------------
ResultSet rs = foo();
 while(rs.next() {
     /*do something */
}
rs.close();

public ResultSet foo() {

   Statement stmt = con.createStatement();
   stmt.closeOnCompletion();
   ResultSet rs = stmt.executeQuery(aQuery);
   return rs

}
------------------


We did spend a lot of time on this back in 2009 and took quite a bit of time to reach agreement on the current wording.  However, it does  look like there is the potential for some additional word smithing.

Best
Lance



On Feb 17, 2021, at 12:34 PM, Dave Cramer <davecramer at gmail.com<mailto:davecramer at gmail.com>> wrote:

On Wed, 17 Feb 2021 at 12:13, Filipe Silva <filipe.silva at oracle.com<mailto:filipe.silva at oracle.com>> wrote:

On 17/02/21 10:53, Dave Cramer wrote:
Interesting situation.

If we have an open statement with open resultsets and call
closeOnCompletion and then execute the statement a second time the
statement will throw an already closed exception since the spec says that
executing a statement a second time closes any open resultsets. Closing
said resultsets ends up closing the statement.

I'm just confirming that this is the intended behaviour. Seems about
right
since if you set closeOnCompletion you would not expect to re-use the
statement.

Dave Cramer
No, I don't think it is supposed to work like this. "Completion" means
that the user is done with the ResultSet(s) and explicitely calls
close() on it/them.

Successive executions do close previously opened ResultSets but closing
those ResultSets implicitely (by re-executing) do not close the
Statement. The documentation makes it clear when it says "a call to
|closeOnCompletion| does effect both the *subsequent execution of
statements*, (...)". There would be no "subsequent execution of
statements" if the behavior was the one you described.


Well interestingly I'm told that the Oracle driver does close the statement
on subsequent execution.

Either way I'm not sure I agree with the inference. Now we have to debate
the word execution. Is calling the method an execution or is completing the
call an execution ?

Dave Cramer



More information about the jdbc-spec-discuss mailing list