commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject RE: DBCP: Closed connections
Date Fri, 25 Apr 2003 18:29:05 GMT


On Fri, 25 Apr 2003, Robert Egan wrote:

> Date: Fri, 25 Apr 2003 14:00:30 -0400
> From: Robert Egan <regan@ph.com>
> Reply-To: Jakarta Commons Users List <commons-user@jakarta.apache.org>
> To: 'Jakarta Commons Users List' <commons-user@jakarta.apache.org>
> Subject: RE: DBCP: Closed connections
>
> In an effort to muddy the waters more, perhaps some clarification is in
> order.
>
> If a Statement, PreparedStatement, or CallableStatement directly produces a
> ResultSet (via SELECT) then that result set is closed when the associated
> statement is closed.
>
> However, if a result set was produced another way (such as selecting into a
> REF CURSOR) then that result set is not closed, at least in the Oracle
> driver(s).

One other important note -- although closing a Connection is supposed to
close all the related Statements and ResultSets, that still doesn't help
if you're using a connection pool like DBCP.  The reason for this is that
Connection.close() simply puts the connection back into the pool -- the
underlying connection won't actually be closed (because that would defeat
the point of using a pool in the first place).  Therefore, any open
statements and result sets are still open (even if the JDBC driver does
the right thing).

Moral of the story:  ALWAYS close your statements and result sets.

>
> Regrettably, while the JDBC 3.0 specification formally addresses the former
> case in chapter 13.1.3, it appears to be mute on the latter.
>
>
> Robert Egan

Craig

Mime
View raw message