• 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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: 40211
816
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!!
 
Live ordinary life in an extraordinary way. Details embedded in this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic