Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Cannot get a connection, pool exhausted

Posted on 2007-12-04
3
Medium Priority
?
4,196 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 23

Accepted Solution

by:
rama_krishna580 earned 2000 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
In this article, we’ll look at how to deploy ProxySQL.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

730 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