Solved

Cannot get a connection, pool exhausted

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org (http://seleniumhq.org) Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

757 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