Solved

Cannot get a connection, pool exhausted

Posted on 2007-12-04
3
4,159 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
powershell and sql server - alerting 7 77
github account with ecipse 1 42
java jdbc batch example 8 22
eclipse apache tomcat admin console 52 66
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

895 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now