This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
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.
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.
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.