Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

MySQL Connection Pooling

 
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Tomcat and MySQL and connect to a MySQL database through the following code in my servlet (oversimplified for brevity's sake).



A few questions:

Is the method ds.getConnection() getting a connection from a Connection Pool?

If so, what connection pool? I didn't create any classes that pooled connections? Is it handled by the driver vendor (MySQL Connector/J)?

If my above suspicions are correct, do all major driver vendors pool connections for you?

If so, I suppose that for most web enabled Java apps the days of having to manually code classes to pool connections for our apps are over...?

Thanks,
Jim
 
author & internet detective
Posts: 40912
840
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jim,
Typically the a combination of the server and the driver handle the connection pool for you. Tomcat uses DBCP (a project from Jakarta Commons for connection pooling.) All the major vendors certainly provide support. You are correct that for web apps, we don't have to manually pool connections. For a standalone app, we could use DBCP ourselves.
 
Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by James Ellis:

Is the method ds.getConnection() getting a connection from a Connection Pool?

If so, what connection pool? I didn't create any classes that pooled connections? Is it handled by the driver vendor (MySQL Connector/J)?



1. Yes, it is.
2. The connection pool must have been set in the way your context is configured in Tomcat configuration files. The connection pool would either be configured in your Tomcat server.xml file, or your webapp's context file under Tomcat conf/Catalina/localhost directory. Also, in your web.xml, there must be a reference to the connection pool being accessed.

HTH

Sonny
 
reply
    Bookmark Topic Watch Topic
  • New Topic