This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Connection Pooling in tomcat 6" Watch "Connection Pooling in tomcat 6" New topic
Author

Connection Pooling in tomcat 6

Gaurav Wadhwani
Ranch Hand

Joined: Sep 21, 2010
Posts: 68
http://www.java-samples.com/showtutorial.php?tutorialid=621

I read the above tutorial but it doesn't not mention of tomcat 6. Then i Googled about tomcat 6 and got this link http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html.

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
org.gjt.mm.mysql.Driver - 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"
url="jdbc:mysql://localhost:3306/javatest"/>


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


and
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/TestDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>


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
http://commons.apache.org/dbcp/apidocs/index.html
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: 15950
    
  19

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 tomcat.apache.org 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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Connection Pooling in tomcat 6
 
Similar Threads
java.sql.SQLException: No suitable driver found
Configuring a MySQL DataSource in Tomcat5
~~ Newbie question - database ~~
java.sql.SQLException: No suitable driver
DataSource Invalid