• 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Getting a "connection is already closed" exception with 2 or more users

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was testing my code today with 2 users and got the following error when we both clicked the same link.

java.sql.SQLException: Connection has already been closed.

the method that is run when that link is clicked goes like this.

opens a connection (using connection pools)
runs sql
puts data into java object
closes connection.

when using connection pools, am I not supposed to close my connections? Is that all handled by the webserver? Here is an example method.



Maybe I'm not using the pool correctly in my code when opening it?

I open my connection by:



And I close it by:






Any help would be greatly appreciated.

-Nate
 
author & internet detective
Posts: 39789
797
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nate,
Do both users have access to the same instance of this class? If so, there are thread conflicts because instance variables aren't thread safe.
 
Nate Leech
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah ha!

Thanks! That was my problem. Gah, well I feel like a fool.

Will never make that mistake again

Thanks!!
 
I miss the old days when I would think up a sinister scheme for world domination and you would show a little emotional support. So just look at this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!