Dave Cramer davecramer at
Wed Feb 17 13:35:20 UTC 2021

On Wed, 17 Feb 2021 at 08:25, Mark Rotteveel <mark at> wrote:

> 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
> 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.
In this case the results are being closed as a result of executing the
statement again.
I do not think that is at odds with the documentation. That said the docs
are certainly not explicit.

It does say that calling closeOnCompletion affects the current statement
and any dependent result sets.


> Mark

More information about the jdbc-spec-discuss mailing list