You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by Deepa Remesh <dr...@gmail.com> on 2006/01/11 23:07:25 UTC

Question about closing connection and statement objects

Should a JDBC driver close the statement objects associated with a
connection when the connection's close() method is called?

I saw this in JDBC 3.0 spec (Section 13.1.3 Closing Statement Objects)
"All Statement objects will be closed when the connection that created
them is closed." But I found different behaviour with Derby embedded
and client driver. When using embedded driver, it does not close the
associated statement objects when connection.close() is called. In
client driver, the connection object maintains a list of all open
statements and closes them when connection.close() is called.

I'd appreciate if someone can explain this difference and which
behaviour is correct.

Thanks,
Deepa

Re: Question about closing connection and statement objects

Posted by "Lance J. Andersen" <La...@Sun.COM>.
Connection.close() is supposed to close open Statement objects.

Deepa Remesh wrote:

>Should a JDBC driver close the statement objects associated with a
>connection when the connection's close() method is called?
>
>I saw this in JDBC 3.0 spec (Section 13.1.3 Closing Statement Objects)
>"All Statement objects will be closed when the connection that created
>them is closed." But I found different behaviour with Derby embedded
>and client driver. When using embedded driver, it does not close the
>associated statement objects when connection.close() is called. In
>client driver, the connection object maintains a list of all open
>statements and closes them when connection.close() is called.
>
>I'd appreciate if someone can explain this difference and which
>behaviour is correct.
>
>Thanks,
>Deepa
>  
>

Re: Question about closing connection and statement objects

Posted by Deepa Remesh <dr...@gmail.com>.
On 1/11/06, Daniel John Debrunner <dj...@apache.org> wrote:
> Deepa Remesh wrote:
> > Should a JDBC driver close the statement objects associated with a
> > connection when the connection's close() method is called?
> >
> > I saw this in JDBC 3.0 spec (Section 13.1.3 Closing Statement Objects)
> > "All Statement objects will be closed when the connection that created
> > them is closed." But I found different behaviour with Derby embedded
> > and client driver. When using embedded driver, it does not close the
> > associated statement objects when connection.close() is called. In
> > client driver, the connection object maintains a list of all open
> > statements and closes them when connection.close() is called.
> >
> > I'd appreciate if someone can explain this difference and which
> > behaviour is correct.
>
> I think you are seeing different implementations, but the behaviour is
> the same. The close of the connection in embedded implicitly closes the
> Statement object. Once an embedded connection is closed, any call on a
> Statement object will result in an exception indicating the object is
> closed.

Yes, the end result is same. I cannot do anything with the embedded
statement after it's connection has been closed. When I call any
method on the statement, embedded driver checks the status of the
statement's connection by calling Connection.isClosed() method and
returns a "No current connection" exception if the connection has been
closed. With the client driver, I get "Invalid operation: statement
closed" exception.

Thanks for the responses.

Deepa

Re: Question about closing connection and statement objects

Posted by Daniel John Debrunner <dj...@apache.org>.
Deepa Remesh wrote:
> Should a JDBC driver close the statement objects associated with a
> connection when the connection's close() method is called?
> 
> I saw this in JDBC 3.0 spec (Section 13.1.3 Closing Statement Objects)
> "All Statement objects will be closed when the connection that created
> them is closed." But I found different behaviour with Derby embedded
> and client driver. When using embedded driver, it does not close the
> associated statement objects when connection.close() is called. In
> client driver, the connection object maintains a list of all open
> statements and closes them when connection.close() is called.
> 
> I'd appreciate if someone can explain this difference and which
> behaviour is correct.

I think you are seeing different implementations, but the behaviour is
the same. The close of the connection in embedded implicitly closes the
Statement object. Once an embedded connection is closed, any call on a
Statement object will result in an exception indicating the object is
closed.

Dan.