Re: Jdbc3PoolingDataSource and Statement relationship???

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: Derek Dilts <ddilts(at)cisco(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Jdbc3PoolingDataSource and Statement relationship???
Date: 2004-02-28 23:33:38
Message-ID: 40412552.9030409@opencloud.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Derek Dilts wrote:
> To whom it may concern:
>
> I am getting a Connection from Jdbc3PoolingDataSource.getConnection(),
> creating and executing a statement, then making a call to
> Connection.close().
>
> My question is this ... are those statements being closed by Postgres's
> pooling implementation like they should be, or do I have to keep track
> and close each Statement b/4 closing the Connection.

You should close your Statements when you no longer need them as a
matter of course -- they may be holding DB resources your application is
not avare of.

> I have read the documentation about pooling and Postgres's
> implementation of the DataSource interface,
> http://www.postgresql.org/docs/7.3/static/jdbc-datasource.html. I am
> aware that by using the pool, Connections actually never close and
> remain open for the life of the pool. However, I am assuming that when
> my application calls Connection.close(), any associated Statements will
> be cleaned-up/closed. Is this assumption correct? If so, please point me
> to any documentation that might explain this. If not, please advise!

Connection.close() seems to have different semantics when the
implementation is one returned by a PoolingConnection (although the spec
is, as always, annoyingly vague about it). Namely, closing such a
connection obviously *doesn't* release all the DB/JDBC resources
associated with it (as Connection.close() claims), since the underlying
connection is not actually physically closed. The driver may also be
doing statement pooling, in which case it doesn't make sense to close
down Statements whenever a connection pool client returns the connection
to the pool.

So -- I wouldn't rely on it. Close your Statements by hand when you no
longer need them.

-O

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Oliver Jowett 2004-02-28 23:53:53 Re: Connection pools with LOB?
Previous Message Oliver Jowett 2004-02-28 23:25:32 Re: Postgres 7.4.1 JDBC Question