You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Marcelo Epstein <ma...@epstein.com.br> on 2004/04/06 18:31:14 UTC

Re: Connection Pooling (How i use...)

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" <La...@plumcreek.com> escreveu:

> De: "Larry Meadors" <La...@plumcreek.com>
> Data: Tue, 06 Apr 2004 10:19:15 -0600
> Para: <us...@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


Re: Connection Pooling (How i use...)

Posted by Paul Barry <pa...@nyu.edu>.
Yes, you need to put the conn.close() in a finally, something like this

Connection conn = null;
try {
     ...
     conn = ds.getConnection();
     ...
} catch(Exception ex) {

} finally {
     try {
      conn.close();
     } catch(Exception ex) {
          System.err.println(ex);
     }
}

In your way, if there is an exception, the connection will not be 
closed, because the code will not reach the conn.close() statement.

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" <La...@plumcreek.com> escreveu:
> 
> 
>>De: "Larry Meadors" <La...@plumcreek.com>
>>Data: Tue, 06 Apr 2004 10:19:15 -0600
>>Para: <us...@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


Re: Connection Pooling - Monitor

Posted by Marcelo Epstein <ma...@epstein.com.br>.
Richard,

I am already setting autoReconnect=true. I just want to know if exists any method that returns the # of opened connections are in the pool.

Thanks. 




On Tue, 6 Apr 2004 10:54:06 -0700 (PDT), Richard Yee <ry...@yahoo.com> escreveu:

> De: Richard Yee <ry...@yahoo.com>
> Data: Tue, 6 Apr 2004 10:54:06 -0700 (PDT)
> Para: Struts Users Mailing List <us...@struts.apache.org>
> Assunto: Re: Connection Pooling - Monitor
> 
> Marcelo,
> The # of connections is determined by the value you
> set when you defined your datasource. What is the URL
> that you are using? You should set autoReconnect=true
> in the URL.
> 
> -Richard
> 
> 
> 
> --- Marcelo Epstein <ma...@epstein.com.br> wrote:
> > 
> > Is it possible to know how many connection are in
> > the pool ? Is there any monitor available?
> > 
> > 
> > On Tue,  6 Apr 2004 14:15:34 -0300, "Marcelo
> > Epstein" <ma...@epstein.com.br> escreveu:
> > 
> > > De: "Marcelo Epstein" <ma...@epstein.com.br>
> > > Data: Tue,  6 Apr 2004 14:15:34 -0300
> > > Para: "Struts Users Mailing List"
> > <us...@struts.apache.org>
> > > Assunto: Re: Connection Pooling (How i use...)
> > > 
> > > Now I am closing the connection in the finally
> > block.
> > > The exemple provided by:
> > >
> >
> http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html
> > > doesn´t do that:
> > > package foo;
> > > 
> > > import javax.naming.*;
> > > import javax.sql.*;
> > > import java.sql.*;
> > > 
> > > public class DBTest {
> > > 
> > >   String foo = "Not Connected";
> > >   int bar = -1;
> > >     
> > >   public void init() {
> > >     try{
> > >       Context ctx = new InitialContext();
> > >       if(ctx == null ) 
> > >           throw new Exception("Boom - No
> > Context");
> > > 
> > >       DataSource ds = 
> > >             (DataSource)ctx.lookup(
> > >                "java:comp/env/jdbc/TestDB");
> > > 
> > >       if (ds != null) {
> > >         Connection conn = ds.getConnection();
> > >               
> > >         if(conn != null)  {
> > >             foo = "Got Connection
> > "+conn.toString();
> > >             Statement stmt =
> > conn.createStatement();
> > >             ResultSet rst = 
> > >                 stmt.executeQuery(
> > >                   "select id, foo, bar from
> > testdata");
> > >             if(rst.next()) {
> > >                foo=rst.getString(2);
> > >                bar=rst.getInt(3);
> > >             }
> > >             conn.close();
> > >         }
> > >       }
> > >     }catch(Exception e) {
> > >       e.printStackTrace();
> > >     }
> > >  }
> > > 
> > >  public String getFoo() { return foo; }
> > >  public int getBar() { return bar;}
> > > }
> > > 
> > > 
> > > 
> > > 
> > > On Tue, 06 Apr 2004 12:50:29 -0400, "Geeta Ramani"
> > <ge...@cmpco.com> escreveu:
> > > 
> > > > De: "Geeta Ramani" <ge...@cmpco.com>
> > > > Data: Tue, 06 Apr 2004 12:50:29 -0400
> > > > Para: Struts Users Mailing List
> > <us...@struts.apache.org>
> > > > Assunto: Re: Connection Pooling (How i use...)
> > > > 
> > > > 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" <La...@plumcreek.com> escreveu:
> > > > >
> > > > > > De: "Larry Meadors"
> > <La...@plumcreek.com>
> > > > > > Data: Tue, 06 Apr 2004 10:19:15 -0600
> > > > > > Para: <us...@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
> > > > 
> > > > 
> > > > 
> > > > 
> > > 
> > >
> >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> > user-unsubscribe@struts.apache.org
> > 
> === message truncated ===
> 
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! Small Business $15K Web Design Giveaway 
> http://promotions.yahoo.com/design_giveaway/
> 
> ---------------------------------------------------------------------
> 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


Re: Connection Pooling - Monitor

Posted by Richard Yee <ry...@yahoo.com>.
Marcelo,
The # of connections is determined by the value you
set when you defined your datasource. What is the URL
that you are using? You should set autoReconnect=true
in the URL.

-Richard



--- Marcelo Epstein <ma...@epstein.com.br> wrote:
> 
> Is it possible to know how many connection are in
> the pool ? Is there any monitor available?
> 
> 
> On Tue,  6 Apr 2004 14:15:34 -0300, "Marcelo
> Epstein" <ma...@epstein.com.br> escreveu:
> 
> > De: "Marcelo Epstein" <ma...@epstein.com.br>
> > Data: Tue,  6 Apr 2004 14:15:34 -0300
> > Para: "Struts Users Mailing List"
> <us...@struts.apache.org>
> > Assunto: Re: Connection Pooling (How i use...)
> > 
> > Now I am closing the connection in the finally
> block.
> > The exemple provided by:
> >
>
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html
> > doesn�t do that:
> > package foo;
> > 
> > import javax.naming.*;
> > import javax.sql.*;
> > import java.sql.*;
> > 
> > public class DBTest {
> > 
> >   String foo = "Not Connected";
> >   int bar = -1;
> >     
> >   public void init() {
> >     try{
> >       Context ctx = new InitialContext();
> >       if(ctx == null ) 
> >           throw new Exception("Boom - No
> Context");
> > 
> >       DataSource ds = 
> >             (DataSource)ctx.lookup(
> >                "java:comp/env/jdbc/TestDB");
> > 
> >       if (ds != null) {
> >         Connection conn = ds.getConnection();
> >               
> >         if(conn != null)  {
> >             foo = "Got Connection
> "+conn.toString();
> >             Statement stmt =
> conn.createStatement();
> >             ResultSet rst = 
> >                 stmt.executeQuery(
> >                   "select id, foo, bar from
> testdata");
> >             if(rst.next()) {
> >                foo=rst.getString(2);
> >                bar=rst.getInt(3);
> >             }
> >             conn.close();
> >         }
> >       }
> >     }catch(Exception e) {
> >       e.printStackTrace();
> >     }
> >  }
> > 
> >  public String getFoo() { return foo; }
> >  public int getBar() { return bar;}
> > }
> > 
> > 
> > 
> > 
> > On Tue, 06 Apr 2004 12:50:29 -0400, "Geeta Ramani"
> <ge...@cmpco.com> escreveu:
> > 
> > > De: "Geeta Ramani" <ge...@cmpco.com>
> > > Data: Tue, 06 Apr 2004 12:50:29 -0400
> > > Para: Struts Users Mailing List
> <us...@struts.apache.org>
> > > Assunto: Re: Connection Pooling (How i use...)
> > > 
> > > 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" <La...@plumcreek.com> escreveu:
> > > >
> > > > > De: "Larry Meadors"
> <La...@plumcreek.com>
> > > > > Data: Tue, 06 Apr 2004 10:19:15 -0600
> > > > > Para: <us...@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
> > > 
> > > 
> > > 
> > > 
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> 
=== message truncated ===


__________________________________
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway 
http://promotions.yahoo.com/design_giveaway/

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


Connection Pooling - Monitor

Posted by Marcelo Epstein <ma...@epstein.com.br>.
Is it possible to know how many connection are in the pool ? Is there any monitor available?


On Tue,  6 Apr 2004 14:15:34 -0300, "Marcelo Epstein" <ma...@epstein.com.br> escreveu:

> De: "Marcelo Epstein" <ma...@epstein.com.br>
> Data: Tue,  6 Apr 2004 14:15:34 -0300
> Para: "Struts Users Mailing List" <us...@struts.apache.org>
> Assunto: Re: Connection Pooling (How i use...)
> 
> Now I am closing the connection in the finally block.
> The exemple provided by:
> http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html
> doesn´t do that:
> package foo;
> 
> import javax.naming.*;
> import javax.sql.*;
> import java.sql.*;
> 
> public class DBTest {
> 
>   String foo = "Not Connected";
>   int bar = -1;
>     
>   public void init() {
>     try{
>       Context ctx = new InitialContext();
>       if(ctx == null ) 
>           throw new Exception("Boom - No Context");
> 
>       DataSource ds = 
>             (DataSource)ctx.lookup(
>                "java:comp/env/jdbc/TestDB");
> 
>       if (ds != null) {
>         Connection conn = ds.getConnection();
>               
>         if(conn != null)  {
>             foo = "Got Connection "+conn.toString();
>             Statement stmt = conn.createStatement();
>             ResultSet rst = 
>                 stmt.executeQuery(
>                   "select id, foo, bar from testdata");
>             if(rst.next()) {
>                foo=rst.getString(2);
>                bar=rst.getInt(3);
>             }
>             conn.close();
>         }
>       }
>     }catch(Exception e) {
>       e.printStackTrace();
>     }
>  }
> 
>  public String getFoo() { return foo; }
>  public int getBar() { return bar;}
> }
> 
> 
> 
> 
> On Tue, 06 Apr 2004 12:50:29 -0400, "Geeta Ramani" <ge...@cmpco.com> escreveu:
> 
> > De: "Geeta Ramani" <ge...@cmpco.com>
> > Data: Tue, 06 Apr 2004 12:50:29 -0400
> > Para: Struts Users Mailing List <us...@struts.apache.org>
> > Assunto: Re: Connection Pooling (How i use...)
> > 
> > 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" <La...@plumcreek.com> escreveu:
> > >
> > > > De: "Larry Meadors" <La...@plumcreek.com>
> > > > Data: Tue, 06 Apr 2004 10:19:15 -0600
> > > > Para: <us...@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
> > 
> > 
> > 
> > 
> 
> ---------------------------------------------------------------------
> 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


Re: Connection Pooling (How i use...)

Posted by Mark Lowe <ma...@boxstuff.com>.
Marcelo

Could you do me the huge favor of keeping the version 3 drivers for  
another 20 hours but with the changes you've made (finally block  
stuff)..

And tell us what happens in 20 or so hours. I'd be very interested in  
what you find.

On 6 Apr 2004, at 19:15, Marcelo Epstein wrote:

> Now I am closing the connection in the finally block.
> The exemple provided by:
> http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource- 
> examples-howto.html
> doesn´t do that:
> package foo;
>
> import javax.naming.*;
> import javax.sql.*;
> import java.sql.*;
>
> public class DBTest {
>
>   String foo = "Not Connected";
>   int bar = -1;
>
>   public void init() {
>     try{
>       Context ctx = new InitialContext();
>       if(ctx == null )
>           throw new Exception("Boom - No Context");
>
>       DataSource ds =
>             (DataSource)ctx.lookup(
>                "java:comp/env/jdbc/TestDB");
>
>       if (ds != null) {
>         Connection conn = ds.getConnection();
>
>         if(conn != null)  {
>             foo = "Got Connection "+conn.toString();
>             Statement stmt = conn.createStatement();
>             ResultSet rst =
>                 stmt.executeQuery(
>                   "select id, foo, bar from testdata");
>             if(rst.next()) {
>                foo=rst.getString(2);
>                bar=rst.getInt(3);
>             }
>             conn.close();
>         }
>       }
>     }catch(Exception e) {
>       e.printStackTrace();
>     }
>  }
>
>  public String getFoo() { return foo; }
>  public int getBar() { return bar;}
> }
>
>
>
>
> On Tue, 06 Apr 2004 12:50:29 -0400, "Geeta Ramani"  
> <ge...@cmpco.com> escreveu:
>
>> De: "Geeta Ramani" <ge...@cmpco.com>
>> Data: Tue, 06 Apr 2004 12:50:29 -0400
>> Para: Struts Users Mailing List <us...@struts.apache.org>
>> Assunto: Re: Connection Pooling (How i use...)
>>
>> 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"  
>>> <La...@plumcreek.com> escreveu:
>>>
>>>> De: "Larry Meadors" <La...@plumcreek.com>
>>>> Data: Tue, 06 Apr 2004 10:19:15 -0600
>>>> Para: <us...@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
>>
>>
>>
>>
>
> ---------------------------------------------------------------------
> 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


Re: Connection Pooling (How i use...)

Posted by Geeta Ramani <ge...@cmpco.com>.
Ah, well, you didn't read the fine print:

-->>Note: this code isn't anywhere near production ready - it's only supposed to be used as a simple test :-)

Believe me, you should close connections/return them to the pool in a finally block if you want to avoid major
problems.. As I said before, this issue was discussed in detail and in fcat the person with the initial
question did a real nice write-up of her conclusions.. I think it will be well worth you while to read that
thread..

Regards,
Geeta

Marcelo Epstein wrote:

> Now I am closing the connection in the finally block.
> The exemple provided by:
> http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html
> doesn´t do that:


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


RE: Connection Pooling (How i use...)

Posted by Navjot Singh <na...@net4india.net>.
See this

 Connection conn = null;
  try{
  conn = ds.getConnection();
 
  ...whatever you wish to do with conn..
  catch(SQLException sqle)
  {
    action of exception
  }
  finally{
	try{
            if(nul != conn) conn.close();
	}
	catch(SQLException sqle){ action of exception , may bejust ignore}
}

HTH
Navjot Singh

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


Re: Connection Pooling (How i use...)

Posted by Marcelo Epstein <ma...@epstein.com.br>.
Now I am closing the connection in the finally block.
The exemple provided by:
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html
doesn´t do that:
package foo;

import javax.naming.*;
import javax.sql.*;
import java.sql.*;

public class DBTest {

  String foo = "Not Connected";
  int bar = -1;
    
  public void init() {
    try{
      Context ctx = new InitialContext();
      if(ctx == null ) 
          throw new Exception("Boom - No Context");

      DataSource ds = 
            (DataSource)ctx.lookup(
               "java:comp/env/jdbc/TestDB");

      if (ds != null) {
        Connection conn = ds.getConnection();
              
        if(conn != null)  {
            foo = "Got Connection "+conn.toString();
            Statement stmt = conn.createStatement();
            ResultSet rst = 
                stmt.executeQuery(
                  "select id, foo, bar from testdata");
            if(rst.next()) {
               foo=rst.getString(2);
               bar=rst.getInt(3);
            }
            conn.close();
        }
      }
    }catch(Exception e) {
      e.printStackTrace();
    }
 }

 public String getFoo() { return foo; }
 public int getBar() { return bar;}
}




On Tue, 06 Apr 2004 12:50:29 -0400, "Geeta Ramani" <ge...@cmpco.com> escreveu:

> De: "Geeta Ramani" <ge...@cmpco.com>
> Data: Tue, 06 Apr 2004 12:50:29 -0400
> Para: Struts Users Mailing List <us...@struts.apache.org>
> Assunto: Re: Connection Pooling (How i use...)
> 
> 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" <La...@plumcreek.com> escreveu:
> >
> > > De: "Larry Meadors" <La...@plumcreek.com>
> > > Data: Tue, 06 Apr 2004 10:19:15 -0600
> > > Para: <us...@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
> 
> 
> 
> 

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


Re: Connection Pooling (How i use...)

Posted by Geeta Ramani <ge...@cmpco.com>.
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" <La...@plumcreek.com> escreveu:
>
> > De: "Larry Meadors" <La...@plumcreek.com>
> > Data: Tue, 06 Apr 2004 10:19:15 -0600
> > Para: <us...@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