| Author |
Storing DB access data in the DD
|
Vopli Vidoplyasova
Greenhorn
Joined: Jun 05, 2008
Posts: 26
|
|
I'm writing a small model 1 web application - several JSP's and Servlets and a database. I set up the DB connection in a context listener and save Connection object as a context attribute for the servlets to access (is that right?). Obviously I don't want to hardcode the db access stuff like url and password into the listener, so I was wondering is it safe to keep it in the deployment descriptor as context parameters or I should put it somewhere else?
Thank you!
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56229
|
|
Slava Golovachenko wrote:I set up the DB connection in a context listener and save Connection object as a context attribute for the servlets to access (is that right?).
Not a good approach. This holds a connection open -- an expensive resource -- for the entire lifetime of the web application, and you are going to run into contention and synchronization issues.
You'd be much better off using a connection pool. Are you using Tomcat? It comes with any easy-to-use container-managed connection pool built right in.
|
 |
Vopli Vidoplyasova
Greenhorn
Joined: Jun 05, 2008
Posts: 26
|
|
Bear Bibeault wrote:Not a good approach. This holds a connection open -- an expensive resource -- for the entire lifetime of the web application, and you are going to run into contention and synchronization issues.
You'd be much better off using a connection pool. Are you using Tomcat? It comes with any easy-to-use container-managed connection pool built right in.
Thanks for the fast answer! No, I'm on GlassFish 3 right now. Gotta search for some info on using connection pools with it...
Still what about storing passwords in the DD, is it considered a good practice?
|
 |
Vopli Vidoplyasova
Greenhorn
Joined: Jun 05, 2008
Posts: 26
|
|
|
Well, I successfully created a connection pool. I guess the question about passwords in the DD is not relevant anymore)) The only thing is, how do I access the connection from a servlet now? Also, do I need this listener at all if all I was using it for was setting up the connection?
|
 |
 |
|
|
subject: Storing DB access data in the DD
|
|
|