permaculture playing cards*
The moose likes Tomcat and the fly likes connection pooling with Tomcat 4.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "connection pooling with Tomcat 4.0" Watch "connection pooling with Tomcat 4.0" New topic
Author

connection pooling with Tomcat 4.0

Narsimha Manekar
Ranch Hand

Joined: Mar 05, 2001
Posts: 35
Hi
I am trying to use connection pooling with
Tomcat 4.0.6
J2SDK 1.4.0
mysql server version: 4.1.0-alpha
JDBCdriver mysql-connector-java-3.0.8-stable-bin.jar
For this I am trying to use the example provided in
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html
but couldn't get it to work.
Could any one give me a step by step procedure to implement connection pooling with Tomcat 4.0.6 / DBCP / mysql
Thank you.
Rao
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

Moving to the Tomcat forum.
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
sudeep philip
Greenhorn

Joined: Nov 28, 2002
Posts: 5
Hi,
I tried out the connection pool on Apache Tomcat/4.1.10 and was sucessfull. The databases which was tested was Oracle 9i and SQL Server 7/2000 databases.
Hope this will solve your problems....
1) The commons-dbcp-1.1.jar, commons-pool-1.1.jar and commons-collections.jar should be at Tomcat/common/lib folder.
2) The jdbc driver,(mysql-connector-java-3.0.8-stable-bin.jar) should be available at Tomcat/common/lib folder.
3) Add the Resource name and the following details within the context at Tomcat/conf/server.xml
<Resource name="YourPoolName" scope="Shareable" type="javax.sql.DataSource" auth="Container"/>
<ResourceParams name="YourPoolName">
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost:3306/dbname?autoReconnect=true</value>
</parameter>
<parameter>
<name>validationQuery</name>
<value></value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>5</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>-1</value>
</parameter>
<parameter>
<name>username</name>
<value>Database UserName</value>
</parameter>
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>password</name>
<value>database password</value>
</parameter>
</ResourceParams>
4) From the program use the following lines to access the pool.
javax.naming.InitialContext ctx = new javax.naming.InitialContext();
javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("java:/comp/env/YourPoolName");
java.sql.Connection con=ds.getConnection();
5) Restart tomcat. :-))
Note: Check for the driver and data base url. Hope this will solve your problem of creating a connection pool for tomcat.
[ January 02, 2004: Message edited by: sudeep philip ]
[ January 02, 2004: Message edited by: sudeep philip ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: connection pooling with Tomcat 4.0
 
Similar Threads
tomcat related query
load DB connection class on tomcat startup
Connection Pool/App Server
connection pooling
JNDI in Servlets