Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Serlvets DB connection pool optimal implementation?  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!