Solved

Cannot get a connection, pool exhausted

Posted on 2007-12-04
3
4,178 Views
Last Modified: 2013-12-15
Hi,
I'm getting the error "Cannot get a connection, pool exhausted" every time when i try to cal a function in my Struts Action.
When first time accessing the first method of any DAO file, it is executing successfully where when i try to call a second method it showing the error:
"org.apache.commons.dbcp.SQLNestedException:Cannot get a connection, pool exhausted.
Caused by: java.util.NoSuchElementException: Timeout waiting for idle object"

I have released all the connection... Please help me in this regard.

Below my DAO file:

public LinkedList getListarUsuariosCelula(Conexao conexao, int idCelula) throws Exception {

            PreparedStatement stmt = null;
            ResultSet rs = null;
            LinkedList list = new LinkedList();
            int[] idUsuarios = new int[15];


            try {
                  stmt = conexao.getConnection().prepareStatement(STMT_USUARIO_CELULA);
                  stmt.setInt(1, idCelula);
                  rs = stmt.executeQuery();

                  for (int i = 0; rs.next(); i++) {
                        idUsuarios[i] = rs.getInt("idUsuario");
                  }

                  for (int i = 0; i < idUsuarios.length; i++) {
                        stmt = conexao.getConnection().prepareStatement(STMT_USUARIO_CELULA_IDUSUARIOS);
                        stmt.setInt(1, idUsuarios[i]);
                        rs = stmt.executeQuery();

                        while(rs.next()){
                              UsuarioGCA  usuarioGCA = new UsuarioGCA();

                              usuarioGCA.setNome(rs.getString("nome"));
                              usuarioGCA.setChave(rs.getString("chave"));

                              list.add(usuarioGCA);
                        }
                  }
            } catch (SQLException e) {
                  e.printStackTrace();
                  throw e;
            } finally {
                  conexao.closeConnection(stmt, rs);
                  conexao.close();
            }
            return list;
      }


my Context.xml file:

<Context path="/gepla" reloadable="true" docBase="C:\eclipse\workspace\gepla" workDir="C:\eclipse\workspace\gepla\work">
      <Resource name="jdbc/gepla"  auth="Container" type="javax.sql.DataSource" scope="Shareable" removeAbandoned="true" removeAbandonedTimeout="60" logAbandoned="true"/>
      <ResourceParams name="jdbc/gepla">
            <parameter>
            <name>factory</name>
            <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
            </parameter>
            <parameter><name>driverClassName</name><value>com.mysql.jdbc.Driver</value></parameter>
            <parameter><name>url</name><value>jdbc:mysql://172.18.3.229:3306/gepla</value></parameter>
            <parameter><name>username</name><value>root</value></parameter>
            <parameter><name>password</name><value>root</value></parameter>
            <parameter><name>maxActive</name><value>20</value></parameter>
            <parameter><name>maxIdle</name><value>10</value></parameter>
            <parameter><name>maxWait</name><value>100</value></parameter>
      </ResourceParams>
      <Resource name="jdbc/gca"  auth="Container" type="javax.sql.DataSource" scope="Shareable"
      removeAbandoned="true" removeAbandonedTimeout="60" logAbandoned="true"/>
      <ResourceParams name="jdbc/gca">
            <parameter>
            <name>factory</name>
            <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
            </parameter>
            <parameter><name>driverClassName</name><value>com.mysql.jdbc.Driver</value></parameter>
            <parameter><name>url</name><value>jdbc:mysql://172.18.3.229:3306/gca</value></parameter>
            <parameter><name>username</name><value>root</value></parameter>
            <parameter><name>password</name><value>root</value></parameter>
            <parameter><name>maxActive</name><value>20</value></parameter>
            <parameter><name>maxIdle</name><value>10</value></parameter>
            <parameter><name>maxWait</name><value>100</value></parameter>
      </ResourceParams>
</Context>

Thanks.
0
Comment
Question by:lorenadourado
3 Comments
 
LVL 23

Accepted Solution

by:
rama_krishna580 earned 500 total points
ID: 20439768
Try adding these settings...add the following code to ur xml file
<!-- To configure a DBCP DataSource so that abandoned dB connections are removed and recycled add the following paramater to the ResourceParams configuration for your DBCP DataSource Resource: -->

<parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter>

<!--Use the removeAbandonedTimeout parameter to set the number of
seconds a dB connection has been idle before it is considered abandoned. -->

<parameter>
<name>removeAbandonedTimeout</name>
<value>60</value>
</parameter>

<!--The logAbandoned parameter can be set to true if you want DBCP to log a stack trace of the code which abandoned the dB connection resources -->

<parameter>
<name>logAbandoned</name>
<value>true</value>
</parameter>

R.K
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question