File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Serlvets DB connection pool optimal implementation? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Serlvets DB connection pool optimal implementation?" Watch "Serlvets DB connection pool optimal implementation?" New topic
Author

Serlvets DB connection pool optimal implementation?

Joe Anderson
Greenhorn

Joined: Apr 20, 2012
Posts: 1
I've created a pool class (DBPool) to create the connection pool (Tomcat). This class is then initialized by the ServletContextListener class.

It might be good to know that my web system got several servlets, each of them containing up to maybe 20 db queries.

My question is, where should I create the connection?
1. In the beginning of each servlet (in the doPost/doGet section).
Then passing on the conn to each method containing the actual db queries.
One connection will then be used for the entire request, no matter then number of db queries performed.
But where should I close the connection?
2. Before each db query.
Then it will be easy to close the connection. But then loads of connections from the pool will be got and closed for each request.
3. Some other implementation
?

Greetings,
Joe

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Serlvets DB connection pool optimal implementation?
 
Similar Threads
Are JSPs Thread Safe ?
Implementing a query time-out
Re: Closing database connection in destroy metod()?
connection pooling issue in production environment -
Connection Pooling