Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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

 
  • Mark post as helpful
  • send pies
  • 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: 3595
39
  • Mark post as helpful
  • send pies
  • 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.
 
Bartender
Posts: 19657
92
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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: 3595
39
  • Mark post as helpful
  • send pies
  • 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
Bartender
Posts: 19657
92
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!