tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Davison <peterdavi...@rogers.com>
Subject Re: Commons DBCP and closing connections
Date Sat, 24 Aug 2002 02:56:22 GMT
Correct me if I'm wrong but if the first con.close() call succeeds your code
will still execute the second con.close() call in the finally block won't it?

Closing the connection won't necessarily dereference the "con" variable, so it's
trying to close a connection that is already closed, which would explain the
exception you're getting.

P.

On Fri, 23 Aug 2002 19:10:09 -0700
Jakarta Tomcat Newsgroup (@Basebeans.com) <jakarta-tom@basebeans.com> wrote:

> Subject: Commons DBCP and closing connections
> From: Matt Raible <matt@raibledesigns.com>
>  ===
> I am trying to upgrade from using Tyrex 0.9.7 to DBCP (from Struts 1.1 b2) -
> and I have the following method that used to work fine:
> 
>     /** Closes a connection from the connection pool */
>     public void closeConnection(Connection con) throws
> ServiceLocatorException
>     {
>         try {
>             con.close();
>         } catch (SQLException sqle) {
>             logger.error("SQLException: " + sqle.getMessage());
>             throw new ServiceLocatorException(sqle);
>         } finally {
>             if (con != null) {
>                 // try again
>                 try {
>                     con.close();
>                 } catch (SQLException csqle) {
>                     // ignore
>                 }
>             }
>         }
>     }
> 
> But now it causes a "connection closed" error??  I thought when you were
> using a connection pool, "closing" the connection just releases it back to
> the pool.  Am I doing this right??
> 
> Matt
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>
> 


--
Peter Davison
peterdavison@rogers.com

Don't everyone thank me at once!
		-- Han Solo

--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message