• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

org.postgresql.util.PSQLException: This connection has been closed.

 
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting the following exceptions while logging in to my application. I have tried to figure it out but its being hard to find a solution. Please suggest a way to resolve.

 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

   at com.myapp.utils.DataBaseConnection.getStatement(DataBaseConnection.java:117)
   at com.myapp.utils.DataBaseUtils.execute(DataBaseUtils.java:190)


Can you show us the code around here?
I have a suspicion you are holding onto Connection objects in your utility after they've been closed and are attempting to reuse them.
 
Saloon Keeper
Posts: 25466
180
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I read the stack correctly, you're trying to obtain a connection from a Tomcat database connection pool, but the pool connection is closed and therefore useless.

This can happen with a lot of databases where idle connections timeout (and close themselves) if they are not used often enough.

There are options for Tomcat pools that can deal with this, either by "pinging" the connections to keep them alive or by discarding dead ones and creating new replacements. Check the Tomcat docs for details.
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The tomcat connection pool handles that by checking whether the connection is alive or not.
At least it has done for a long time now.

As I said, to me that stack trace seems to imply someone holding onto a connection in their utility class, which you should not do.
 
Tim Holloway
Saloon Keeper
Posts: 25466
180
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, unless default behaviour has changed, the Tomcat connection pool does not do a liveness check by default. Then again, Tomcat 8 switched to a different pool manager, so the documentation should be checked.

I re-read the stack trace and it's possible that a proxied JDBC call is being done rather than a pool fetch. If that's so, my money is on someone having stored a pool Connection object in their session - which, of course, one should never do. Connection is an Interface, and thus not serializable. These days, Tomcat is supposed to reject non-serializable HttpSession objects, but I'm sure there are cases that it doesn't catch.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic