You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by David Graham <dg...@hotmail.com> on 2003/04/18 16:02:55 UTC

Re: exhausted pool

Somewhere you must not be returning the connection.  You could add logging 
statements to the getConexion and close methods to see if a connection isn't 
getting returned.

David



>From: "Dani" <mc...@wanadoo.es>
>Reply-To: "Struts Users Mailing List" <st...@jakarta.apache.org>
>To: "Struts Users Mailing List" <st...@jakarta.apache.org>
>Subject: exhausted  pool
>Date: Fri, 18 Apr 2003 15:48:01 +0200
>
>My connection pool comes exhausted. What's the problem? I'm using mysql.
>
>This is the exception:
>
>java.sql.SQLException: DBCP could not obtain an idle db connection, pool
>exhausted
>
>
>And this is the code I use:
>
>A class OperacionesBD that manages connections and has a method that 
>creates
>a connection:
>
>public void getConexion() throws NamingException, SQLException {
>  if (conexion == null){
>   Context  ctxContexto = null;  // Contexto de conexión
>   DataSource  dtsDataSource;  // Conexión jndi
>    try
>
>     ctxContexto = new InitialContext();
>     dtsDataSource = (DataSource) ctxContexto.lookup ("java:comp/env/jdbc/" 
>+
>dataSource);
>     conexion = dtsDataSource.getConnection();
>    }catch (NamingException e) {
>     e.printStackTrace();
>     conexion = null;
>     throw e;
>    }catch (SQLException e){
>     e.printStackTrace();
>     conexion = null;
>     throw e;
>    }finally
>
>     if ( ctxContexto != null ){
>      try {
>       ctxContexto.close();
>      }catch(Exception
>
>       exctx.printStackTrace();
>      }
>     }
>    }
>  }
>}
>
>The connection is closed here:
>
>public void close() throws SQLException {
>   if (conexion == null){
>    try {
>     conexion.close();
>    } catch (SQLException e) {
>     e.printStackTrace();
>     throw e;
>    }
>   }
>}
>
>Here is an example of OperacionesBD using:
>
>public ArrayList getListaPacientes(String dataSource, String select) throws
>NamingException, SQLException{
>    OperacionesBD conexion = null;
>    // retorno de método
>    ResultadosBD resultados =  null;
>    try {
>     conexion = new OperacionesBD(dataSource);
>     // Realiza la conexión a la base de datos
>     conexion.getConexion();
>
>     // Realiza la consulta que devuelve el resultado en el objeto
>ResultadosBD
>     resultados =  conexion.getData(select, null);
>    }catch(NamingException e){
>     System.out.println("ListaUsuariosBean :: Error en nom bre BD" + e);
>     throw e;
>    }catch (SQLException e) {
>     System.out.println("ListaUsuariosBean :: Error sql BD" + e);
>     throw e;
>    }finally{
>     // Cierre de conexión
>     try {
>      conexion.close();
>     }catch(SQLException e){
>      System.out.println("ListaUsuariosBean :: Error cerrando conexión a 
>BD"
>+ e);
>     }catch (Exception e) {
>      System.out.println("ListaUsuariosBean :: Error cerrando conexión a BD 
>"
>+ e);
>     }
>     // Convierte el resultado en un arrayList de pacientes
>     return resultados.toObjectArray("gsp.struts.bean.PacienteBean");
>    }
>
>   }
>
>
>What's the problem??? Thanks
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*  
http://join.msn.com/?page=features/junkmail


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