Shilpa,

If you are only using a maximum of 5 possible database connections and you
are receiving that kind of SQLNestException error, I recommend you check
your methods to ensure you are releasing the connections back into the pool
when you are finished with them.  I've seen plenty of posts where people
mistakenly returned from a db or dao method and yet they had the release
further down in the code.  A check of your database should show how many
connections are in use and logs can show what action they did last.  That
might help you narrow down your issue with releasing Connections back into
the pool.

Regards,
David

-----Original Message-----
From: Shilpa Nalgonda [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 28, 2004 11:08 AM
To: Struts Users Mailing List
Subject: FW: org.apache.commons.dbcp.SQLNestedException: Cannot get a
connection, pool exhausted, cause:




Hi,  I am getting the timeout exception for connection pooling, i am using
Tomca 4.1 and datasource to retrieve connections.
I am attaching all the soure code and configuration files used in my
application, please suggest where iam doing wrong...

SEVERE: getConnection()--SQLException
org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool
exhausted, cause:
java.util.NoSuchElementException: Timeout waiting for idle object
        at
org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPoo
l.java:801)
        at
org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.ja
va:140)
        at
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:5
18)
        at
com.mypublisher.oemapi.DAO.DBAccess.getConnection(DBAccess.java:47)
        at com.mypublisher.oemapi.DAO.Persister.<init>(Persister.java:46)
        at
com.mypublisher.oemapi.SubmitOrder.SubmitOrder(SubmitOrder.java:61)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at org.apache.xmlrpc.Invoker.execute(Invoker.java:168)
        at
org.apache.xmlrpc.XmlRpcWorker.invokeHandler(XmlRpcWorker.java:123)
        at org.apache.xmlrpc.XmlRpcWorker.execute(XmlRpcWorker.java:185)
        at org.apache.xmlrpc.XmlRpcServer.execute(XmlRpcServer.java:151)
        at org.apache.xmlrpc.XmlRpcServer.execute(XmlRpcServer.java:128)
        at
com.mypublisher.oemapi.xmlrpc.XmlRpcServlet.doPost(XmlRpcServlet.java
============================================================================
===========
server.xml
---------
<!-- JNDI datasource setup to connect to Oracle database for
xmlrpc-oemapi-->
        <Context path="/rpcoemapi" docBase="rpcoemapi"
                debug="5" reloadable="true" crossContext="true" useNaming="true">

        <Logger className="org.apache.catalina.logger.FileLogger"
             prefix="localhost_rpcoemapi_log." suffix=".txt"
             timestamp="true"/>
       <Resource name="jdbc/MYDB"
               auth="Container"
               type="javax.sql.DataSource"/>

        <ResourceParams name="jdbc/MYDB">
        <parameter>
          <name>factory</name>
          <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
        </parameter>

        <!-- Maximum number of dB connections in pool. Make sure you
         configure your mysqld max_connections large enough to handle
         all of your db connections. Set to 0 for no limit.
         -->
        <parameter>
          <name>maxActive</name>
          <value>5</value>
        </parameter>

        <!-- Maximum number of idle dB connections to retain in pool.
         Set to 0 for no limit.
         -->
        <parameter>
         <name>maxIdle</name>
         <value>2</value>
        </parameter>

         <!-- Maximum time to wait for a dB connection to become available
         in ms, in this example 10 seconds. An Exception is thrown if
         this timeout is exceeded.  Set to -1 to wait indefinitely.
         -->
        <parameter>
         <name>maxWait</name>
         <value>10000</value>
        </parameter>

        <!-- MySQL dB username and password for dB connections  -->
        <parameter>
          <name>username</name>
          <value>ioeadmin</value>
        </parameter>
        <parameter>
          <name>password</name>
          <value>ioeadmin</value>
        </parameter>

        <!-- Class name for mm.mysql JDBC driver -->
        <parameter>
          <name>driverClassName</name>
          <value>oracle.jdbc.driver.OracleDriver</value>
        </parameter>

        <!-- The JDBC connection url for connecting to your MySQL dB.
         The autoReconnect=true argument to the url makes sure that the
         mm.mysql JDBC Driver will automatically reconnect if mysqld closed
the
         connection.  mysqld by default closes idle connections after 8
hours.
         -->
        <parameter>
        <name>url</name>
        <value>jdbc:oracle:thin:@ipaddress:1521:MYDB</value>
        </parameter>
</ResourceParams>
</Context>

============================================================================
===================================
DatasourceFactory is a singleton class used to retrieve the datasource from
tomcat using JNDi..and connection is obtained from datasource...
  public static DataSource getInstance() throws SystemException
    {
        if (!isDataSrcAvaliable)
        {
            if (dataSource == null)
            {
                    new DataSourceFactory();
                    doLookUp();
                    isDataSrcAvaliable = true;
            } //end if (dataSource == null)
        }// end if (!isDataSrcAvaliable)
        return dataSource;
    } /* end getInstance() */

doLookUp method does this:
                Context ctx = new InitialContext();
            String dataSrc =
msgResource.getMessage(OEMAPIConstants.DATA_SOURCE_NAME);
            Context env = (Context)ctx.lookup("java:comp/env");
            dataSource = (DataSource) env.lookup(dataSrc);


public static Connection getConnection() throws DAOException
        {
           DataSource ds = (DataSource) DataSourceFactory.getInstance();
           Connection con = ds.getConnection();
           return ds.getConnection();
        }
and every database lookup class, gets this connection and closes the
connection after the query to database...



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to