• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
Do Re Mi Fa So La Tiny Ad
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic