closeOnCompletion

Mark Rotteveel mark at lawinegevaar.nl
Wed Feb 17 13:24:26 UTC 2021


On 2021-02-17 13:19, Mark Rotteveel wrote:
> On 2021-02-17 11: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.
> 
> Logically, yes, I think this is how it is supposed to work. If you
> call closeOnCompletion, you signal that you intended to abandon the
> statement after processing, so if you then go and try to use the
> statement any way, you're doing something wrong.

I also posted an answer to this effect at 
https://stackoverflow.com/a/66242121/466862

However, thinking some more about it, I'm wondering if maybe there is 
something missing in the documentation of closeOnCompletion. I have 
always assumed that it means that the statement must be closed when 
execution completes, but now I'm wondering if it actually means that 
calling close() will delay the actual close of the statement until after 
execution (processing all results) is complete. In other words: maybe 
closeOnCompletion shouldn't do anything until you call close(), at which 
point it will delay the actual close until you have processed all 
results.


Mark


More information about the jdbc-spec-discuss mailing list