Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MySQL Connection Pooling

 
James Ellis
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • 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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34071
331
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic