File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes Connection Pooling in tomcat 6 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Connection Pooling in tomcat 6" Watch "Connection Pooling in tomcat 6" New topic

Connection Pooling in tomcat 6

Gaurav Wadhwani
Ranch Hand

Joined: Sep 21, 2010
Posts: 68

I read the above tutorial but it doesn't not mention of tomcat 6. Then i Googled about tomcat 6 and got this link

This says

Context configuration

Configure the JNDI DataSource in Tomcat by adding a declaration for your resource to your Context.

so should i place

<!-- maxActive: Maximum number of dB connections in pool. Make sure you
configure your mysqld max_connections large enough to handle
all of your db connections. Set to -1 for no limit.

<!-- maxIdle: Maximum number of idle dB connections to retain in pool.
Set to -1 for no limit. See also the DBCP documentation on this
and the minEvictableIdleTimeMillis configuration parameter.

<!-- maxWait: Maximum time to wait for a dB connection to become available
in ms, in this example 10 seconds. An Exception is thrown if
this timeout is exceeded. Set to -1 to wait indefinitely.

<!-- username and password: MySQL dB username and password for dB connections -->

<!-- driverClassName: Class name for the old mm.mysql JDBC driver is - we recommend using Connector/J though.
Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver.

<!-- url: The JDBC connection url for connecting to your MySQL dB.

<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver"

in ..Tomcat 6.0\conf\context.xml ?

<description>DB Connection</description>

in web.xml in WEB-INF . I use Netbeans
debraj mallick
Ranch Hand

Joined: Mar 08, 2011
Posts: 188

Hi Gaurav,

are you looking for DBCP?

this could be helpfull
Gaurav Wadhwani
Ranch Hand

Joined: Sep 21, 2010
Posts: 68
no that does not solve my it
the first link is a doc and second link gives example but its manual connection pooling.

the one i was trying to attempt is easier. I need to only get a connection from the pool in any servlet.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

Leave the IDE out of it.

Tomcat itself doesn't do database connection pooling. It supports plugin poolers. The Apache DBCP pooler is provided as part of the Tomcat distro, however, so that eliminates the need for you to download and install a separate connection pooler unless you really want to.

To the best of my recollection, the same configuration instructions apply for connection poolers (DataSources) for Tomcat 3 all the way up to Tomcat 7 and the instructions on the website are pretty clear, I think.

To create, configure, and use a database connection pooler, you define the datasource(s) in your webapp context definition or in the global server config. That definition specifies the location of the database of interest (URL), its connection credentials and parameters, and whatever pool tuning and diagnostic options you wish to employ. It also binds the DataSource to a jndi name so that the webapp(s) can locate it by an abstract identifier rather than by having to supply specifics within the webapp itself.

In the webapp, you set up a resource-ref in web.xml. The you use JNDI to locate the DataSource whenever you wish. You can do this at startup and cache the DataSource object for later use if you prefer to reduce the JNDI overhead.

An app may employ multiple DataSources. Normally you'd want all connections to a specific database to use the same connection pool, but I have several apps that connect to multiple databases, so each database has a corresponding DataSource.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Connection Pooling in tomcat 6
It's not a secret anymore!