struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geeta Ramani" <geeta.ram...@cmpco.com>
Subject Re: Connection Pooling (How i use...)
Date Tue, 06 Apr 2004 16:50:29 GMT
This your problem: closing the connection in your try block. Move it to a finally block..

Marcelo Epstein wrote:

> I use the pool like this: (IS IT WRONG??) I think the connection is being closed..
>
> try {
>         Context ctx = new InitialContext();
>         if (ctx == null)
>               throw new Exception("Boom - No Context");
>
>               DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/EasyDB");
>
>               if (ds != null) {
>                 Connection conn = ds.getConnection();
>                 if (conn != null) {
>                         Statement stmt = conn.createStatement();
>                         String query ="Any query";
>                         ResultSet rs = stmt.executeQuery(query);
>                         while (rs.next()) {
>                                                               "Use ResulSet"
>
>                         }
>                                 stmt.close();
>                         conn.close();
>                 }
>             }
>         } catch (Exception ex) {
>                 System.out.println(ex.toString());
>         }
>
> On Tue, 06 Apr 2004 10:19:15 -0600, "Larry Meadors" <Larry.Meadors@plumcreek.com>
escreveu:
>
> > De: "Larry Meadors" <Larry.Meadors@plumcreek.com>
> > Data: Tue, 06 Apr 2004 10:19:15 -0600
> > Para: <user@struts.apache.org>
> > Assunto: Re: Connection Pooling
> >
> > My bet is on a connection leak - you open one in a try block and don't close it
in the finally block.
> >
> > >>> marcelo@epstein.com.br 04/06/04 10:08 AM >>>
> > Hi,
> >
> > I have just started using Connection Pooling in my app  (Tomcat, Struts, DBCP, Mysql)
.
> > It woks for about 20 hours and stop working until tomcat restart.
> >
> > I get this exception:
> >
> > org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool exhausted,
cause:
> > java.util.NoSuchElementException: Timeout waiting for idle object
> >
> > I canÌ t fix it. Any advice??
> >
> > Thanks in advance.
> > Marcelo
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message