You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Jakarta Tomcat Newsgroup (@Basebeans.com)" <ja...@basebeans.com> on 2002/08/24 04:10:09 UTC

Commons DBCP and closing connections

Subject: Commons DBCP and closing connections
From: Matt Raible <ma...@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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Commons DBCP and closing connections

Posted by Andrew Conrad <an...@attbi.com>.
That's what I saw.  

- Andrew

> -----Original Message-----
> From: Peter Davison [mailto:peterdavison@rogers.com] 
> Sent: Friday, August 23, 2002 10:56 PM
> To: Tomcat Users List
> Subject: Re: Commons DBCP and closing connections
> 
> 
> 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) 
> <ja...@basebeans.com> wrote:
> 
> > Subject: Commons DBCP and closing connections
> > From: Matt Raible <ma...@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: 
> > <ma...@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: <ma...@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Commons DBCP and closing connections

Posted by Peter Davison <pe...@rogers.com>.
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) <ja...@basebeans.com> wrote:

> Subject: Commons DBCP and closing connections
> From: Matt Raible <ma...@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:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


--
Peter Davison
peterdavison@rogers.com

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

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>