Thread: Closing Statements and ResultSets

Closing Statements and ResultSets

From
Daniel Serodio
Date:
    Hi! I usually close just the Connection object, understanding that it's
associated Statement's, PreparedStatement's and ResultSet's will be
automatically closed.

    I'm trying to setup Protomatter JDBC Connection Pool with PostgreSQL,
and Protomatter's documentation state that "It's also important to make
sure you close all Statement, PreparedStatement and ResultSet objects
associated with a connection before you close the connection itself.".

    I emailed Protomatter's author, and he said that "specifically Oracle
is not good about doing that.  If you don't close the statements you'll
eventually get an error like "can't open any more cursors" or something
like that..."

    My question is: do I need to close the Statements or is closing the
Connection enough?

--
[]'s
Daniel Serodio


Re: Closing Statements and ResultSets

From
Barry Lind
Date:
Daniel,

If you are using virtually any connection pool closing the connection
alone will not be enough.  Because in a connection pool environment
closing a connection doesn't really close the connection, it just
returns it to the pool, thus any resources you haven't closed explicitly
will remain open and allocated.

--Barry

Daniel Serodio wrote:
>     Hi! I usually close just the Connection object, understanding that it's
> associated Statement's, PreparedStatement's and ResultSet's will be
> automatically closed.
>
>     I'm trying to setup Protomatter JDBC Connection Pool with PostgreSQL,
> and Protomatter's documentation state that "It's also important to make
> sure you close all Statement, PreparedStatement and ResultSet objects
> associated with a connection before you close the connection itself.".
>
>     I emailed Protomatter's author, and he said that "specifically Oracle
> is not good about doing that.  If you don't close the statements you'll
> eventually get an error like "can't open any more cursors" or something
> like that..."
>
>     My question is: do I need to close the Statements or is closing the
> Connection enough?
>


Re: Closing Statements and ResultSets

From
Daniel Serodio
Date:
Barry,

Thanks for the reply. But i'm thinking, since the Connection holds
references to it's Statements, it could close the Statements before
returning the Connection to the pool, couldn't it?

On Mon, 2002-09-09 at 18:11, Barry Lind wrote:
> Daniel,
>
> If you are using virtually any connection pool closing the connection
> alone will not be enough.  Because in a connection pool environment
> closing a connection doesn't really close the connection, it just
> returns it to the pool, thus any resources you haven't closed explicitly
> will remain open and allocated.
>
> --Barry
>
> Daniel Serodio wrote:
> >     Hi! I usually close just the Connection object, understanding that it's
> > associated Statement's, PreparedStatement's and ResultSet's will be
> > automatically closed.
> >
> >     I'm trying to setup Protomatter JDBC Connection Pool with PostgreSQL,
> > and Protomatter's documentation state that "It's also important to make
> > sure you close all Statement, PreparedStatement and ResultSet objects
> > associated with a connection before you close the connection itself.".
> >
> >     I emailed Protomatter's author, and he said that "specifically Oracle
> > is not good about doing that.  If you don't close the statements you'll
> > eventually get an error like "can't open any more cursors" or something
> > like that..."
> >
> >     My question is: do I need to close the Statements or is closing the
> > Connection enough?
> >
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
--
[]'s
Daniel Serodio


Re: Closing Statements and ResultSets

From
Barry Lind
Date:
Daniel,

Yes the connection could, but the connection pool cannot.  Connection
pools work by creating a wrapper around the real connection object.  So
when you call close on the connection pool wrapper you are not really
calling close on the connection object.  The connection pool wrapper
doesn't know what statements and result sets are open and thus can't
close them, and you don't want to call close on the real connection
object because this will not only close the statements and result sets
but will really close the connection when makes the connection pool
useless.

This is why the jdbc spec is clear that it is the application coders
responsibility to close statements and result sets when finished using them.

thanks,
--Barry

Daniel Serodio wrote:
> Barry,
>
> Thanks for the reply. But i'm thinking, since the Connection holds
> references to it's Statements, it could close the Statements before
> returning the Connection to the pool, couldn't it?
>
> On Mon, 2002-09-09 at 18:11, Barry Lind wrote:
>
>>Daniel,
>>
>>If you are using virtually any connection pool closing the connection
>>alone will not be enough.  Because in a connection pool environment
>>closing a connection doesn't really close the connection, it just
>>returns it to the pool, thus any resources you haven't closed explicitly
>>will remain open and allocated.
>>
>>--Barry
>>
>>Daniel Serodio wrote:
>>
>>>    Hi! I usually close just the Connection object, understanding that it's
>>>associated Statement's, PreparedStatement's and ResultSet's will be
>>>automatically closed.
>>>
>>>    I'm trying to setup Protomatter JDBC Connection Pool with PostgreSQL,
>>>and Protomatter's documentation state that "It's also important to make
>>>sure you close all Statement, PreparedStatement and ResultSet objects
>>>associated with a connection before you close the connection itself.".
>>>
>>>    I emailed Protomatter's author, and he said that "specifically Oracle
>>>is not good about doing that.  If you don't close the statements you'll
>>>eventually get an error like "can't open any more cursors" or something
>>>like that..."
>>>
>>>    My question is: do I need to close the Statements or is closing the
>>>Connection enough?
>>>
>>
>>
>>---------------------------(end of broadcast)---------------------------
>>TIP 2: you can get off all lists at once with the unregister command
>>    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>