aspose file tools*
The moose likes JDBC and the fly likes Leave connection Open or Close it??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Leave connection Open or Close it???" Watch "Leave connection Open or Close it???" New topic
Author

Leave connection Open or Close it???

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

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.


GenRocket - Experts at Building Test Data
Michael Zalewski
Ranch Hand

Joined: Jun 10, 2002
Posts: 30
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Leave connection Open or Close it???