• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Connection Pooling in tomcat 6

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 188
Hibernate Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gaurav,

are you looking for DBCP?

this could be helpfull
http://commons.apache.org/dbcp/apidocs/index.html
 
Gaurav Wadhwani
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
The moth suit and wings road is much more exciting than taxes. Or this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic