jQuery in Action, 3rd edition
The moose likes JDBC and Relational Databases 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 Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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

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

Supriya khare

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.

Jan Cumps

Joined: Dec 20, 2006
Posts: 2541

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
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.

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

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.

M. Gangadhar
It is sorta covered in the JavaRanch Style Guide.
subject: org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool exhausted
It's not a secret anymore!