• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

"Cannot get a connection" exception

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

I'm developing a web-application using the JSF framework and I'm deploying it on a Apache Tomcat 6.0.18. The server is installed on a CentOS5 Linux server.

Sometime, apparently without any reason I get the following exception:

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot get a connection, pool error Timeout waiting for idle object

and the DB cannot be queried anymore (no more connections possible from my application). The only solutions is to restart Tomcat or the machine.


I'm handling user authentication through the Apache Tomcat DataSourceRealm method. My database is an Oracle XE and as a connector I'm using the one supplied by Oracle ojdbc14.jar.

I open connections to my DB with a JNDI Resource. The configuration (from context.xml) is the following one:



I'm closing every connection through a method that close every previously opened instance of the following classes: Connection, Statement, PreparedStatement, ResultSet. I tried also monitoring the number of connection opened at one time and they never overcome a total of 3.

The same happens with the Tomcat Server given in bundle with NetBeans 6.7.

Below a full stack-trace taken from the catalina.out log file.




Thanks for any help

Luca
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I'm closing every connection through a method that close every previously opened instance of the following classes: Connection, Statement, PreparedStatement, ResultSet. I tried also monitoring the number of connection opened at one time and they never overcome a total of 3.

Recheck that code. The error shows that you are out of connections. Better close Connection, Statement, etc... in the proper place: immediately after use, in a final block.
 
Luca Adamo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jan Cumps wrote:

I'm closing every connection through a method that close every previously opened instance of the following classes: Connection, Statement, PreparedStatement, ResultSet. I tried also monitoring the number of connection opened at one time and they never overcome a total of 3.

Recheck that code. The error shows that you are out of connections. Better close Connection, Statement, etc... in the proper place: immediately after use, in a final block.




Actually I do close everything in the final block. I also tought that there must be an error somewhere, but I can't find it! :P so I was wondering if the reason could be different. I'll recheck my code. Thanks
 
Jan Cumps
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sagar Rohankar suggested to use the logAbandoned property to find leaks.
See this thread: https://coderanch.com/t/465105/JDBC/java/Inputs-needed-writing-tool-resolve
 
Luca Adamo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jan Cumps wrote:Sagar Rohankar suggested to use the logAbandoned property to find leaks.
See this thread: https://coderanch.com/t/465105/JDBC/java/Inputs-needed-writing-tool-resolve



That seems quite interesting...i'll give a try...tahnks!
 
Luca Adamo
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That logAbandoned property actually helped: I found the error; there was one, indeed. Thanks!
 
Wanna see my flashlight? How about this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic