• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Leave connection Open or Close it???

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Michael Zalewski
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • 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
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic