struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hudson Wong" <hudsoncww...@yahoo.com>
Subject Re: JDBC Connection Pooling
Date Tue, 22 May 2001 11:29:54 GMT
For a connection pool, con.close() puts the connection back into the pool
instead of really closing the connection. Thus, you must explicitly close
the statements.
----- Original Message -----
From: "Gregor Rayman" <rayman@i-technology.de>
To: <struts-dev@jakarta.apache.org>
Sent: Saturday, May 19, 2001 2:10 AM
Subject: JDBC Connection Pooling


> Hi, I've just found one subtle problem the Struts implementation
> of DataSource.
>
> My code looks something like this:
>
>       ...
>       Connection con = this.dataSource.getConnection();
>       try {
>         PreparedStatement stmt = con.prepareStatement(sql);
>         stmt.setString(1, id);
>         ResultSet rs = stmt.executeQuery();
>         String result = null;
>         if (rs.next()) {
>           result = rs.getString(1);
>         }
>         return result;
>       } finally {
>         con.close();
>       }
>       ...
>
> Obviously, there is an error. I do not close either the ResultSet
> nor the Statement. But I do close the Connection, so that the
> connection is returned to the DataSource's pool.
>
> I realized my error, because Oracle complained about too many
> open cursors after a while.
>
> Shouldn't the call to con.close() close all open statements or at
> least warn about open ones?
>
> --
> gR


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


Mime
View raw message