| Author |
MySQL Connection Pooling
|
James Ellis
Ranch Hand
Joined: Oct 14, 2004
Posts: 205
|
|
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
internet detective
Marshal
Joined: May 26, 2003
Posts: 26201
|
|
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.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Sonny Gill
Ranch Hand
Joined: Feb 02, 2002
Posts: 1211
|
|
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
|
The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
|
 |
 |
|
|
subject: MySQL Connection Pooling
|
|
|