• 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

Leave connection Open or Close it???

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Up to this point, I have been storing the username and password in a Vector that I access whenever I need a connection to the Database. When I am done with the connection, I close the connection.
I was wondering what would be the problems in cretaing a single connection when the user logs into the database, and just keeping it open for the lifetime of the application running? And then close the connection when the user disconnects from the database.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Creating a single connection is not terrible if you have a small scale app, where you know the servlet will only ever be executed one at a time.
But as you add more functionality to your application, you will find the need to have more and more connections. And if two users access your connection simultaneously, things might not work well.
A better solution is to use 'Connection Pooling'. Then just continue to open and close the connection as if you only had to serve a single page.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply. However, this is an application, so each user will have their own Connection on their PC. So there is no need to worry about sharing connections or more than one person using a connection at one time.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic