Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Nate Leech
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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • 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!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic