aspose file tools*
The moose likes JDBC and the fly likes org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool exhausted Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool exhausted" Watch "org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool exhausted" New topic
Author

org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool exhausted

Supriya khare
Greenhorn

Joined: Jul 19, 2008
Posts: 10
I am getting the following exception while using org.apache.commons.dbcp.ConnectionFactory for my Swing base Java application.

Database Error: Cannot get a connection, pool exhausted
Unexpected error has occured, the request can't be processed.
org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool exhausted
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:103)
at adsclient.DBAccess.SQLManager.queryDB(SQLManager.java:388)
at adsclient.AdsGUI.AttackerListPanel$13.construct(AttackerListPanel.java:1009)
at adsclient.AdsGUI.SwingWorker$2.run(SwingWorker.java:158)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.util.NoSuchElementException: Timeout waiting for idle object
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:825)
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:95)

I am not sure how to fix it.


Smileyk
SCJP5
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2477
    
    7

You are using more connections in your application than available in the pool.
This can because you have configured the pool too small, or
because you do not properly close your connections after use.

If you use pooling, the best pattern is to use the connection only for a short time:
get connection from pool
use connection for a short job
close your connection


OCUP UML fundamental and ITIL foundation
youtube channel
ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
This error indicates that you are not closing connections properly and thus, it exceeds the number of available connections from the connection pool. It is a good practice to close result set, statement and connections properly to avoid this exception.


Cheers!!!
Ujjwal B Soni <baroda, gujarat, india> <+919909981973>
"Helping hands are better than praying lips......"
Methari Gangadhar
Greenhorn

Joined: May 15, 2011
Posts: 12
Hi all,

Thanks for the reply, i had same problem then i checked my code where am calling one method to another class method there again getting connection from datasource and its increasing the connections which i have specified in the configuration file, then i realized to increase the connections to as many times am using that didnt solved my problem again giving same error.

Then thought creating/ getting connection from datasource in main method (stating of the program) and pass the connection object to other called methods then it solved my problem and i have tested stress test like generating extracts about 1k with out any error.

Hi Supriya,

You can check your code it will be good to open connection for thread and use that connection entire that thread and close at the end.

hope this will be help full.


Thanks,
M. Gangadhar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool exhausted
 
Similar Threads
Can Not Keep Tomcat Up and running ~30 mins
Sharing a Spring BeanFactory across two servlet contexts
Connection Pooling - exhausted pool problem
Cannot get a connection, pool error Timeout waiting for idle object
tomcat connection pool exception ,help!