aspose file tools*
The moose likes Tomcat and the fly likes Connection pooling problem in Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Connection pooling problem in Tomcat" Watch "Connection pooling problem in Tomcat" New topic
Author

Connection pooling problem in Tomcat

Ganesh Chandrasekaran
Greenhorn

Joined: Nov 14, 2000
Posts: 22
Hi,


Can some one help me with the connection pooling problem in Tomcat5.*

I get the message
Cannot connect to database serverorg.apache.tomcat.dbcp.dbcp.SQLNestedException:
Cannot create JDBC driver of class '' for connect URL 'null'


I have updated the server.xml and web.xml files as per the document

In server.xml between the <Host></Host> tags i have added the following

<DefaultContext>
<Resource name="jdbctestprojectDB" auth="Container" type="javax.sql.DataSource"/>

<ResourceParams name="jdbctestprojectDB">
<parameter>
<name>driverClassName</name>
<value>com.mysql.jdbc.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:mysql://localhost/testproject</value>
</parameter>
<parameter>
<name>username</name>
<value>dev1</value>
</parameter>
<parameter>
<name>password</name>
<value>dev1</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>30</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
<parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter>
<parameter>
<name>removeAbandonedTimeout</name>
<value>120</value>
</parameter>

</ResourceParams>
</DefaultContext>


AND in web.xml added the following between <web-app></web-app> tags


<resource-ref>
<res-ref-name>jdbctestprojectDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>



And in the Jsp page the code is

<%@ page import="java.util.Date" %>
<%@ page import="java.sql.*" %>
<%@ page import="javax.sql.*" %>
<%@ page import="javax.naming.*" %>

<%
try
{
Context initContext = new InitialContext();

Context envContext = (Context)initContext.lookup("java:/comp/env");

DataSource ds = (DataSource)envContext.lookup("jdbctestprojectDB");

Connection conn = ds.getConnection();


Thanks,

Ganesh
Rama Krishna Ghanta
Ranch Hand

Joined: Nov 20, 2006
Posts: 59
check whether you have the proper mysql jar file in your classpath. Also I don't think you should use InitialContext and lookup if you are working with Tomcat. We normally use these if we are doing Connection Pooling in an Application server.


Ram...
Ganesh Chandrasekaran
Greenhorn

Joined: Nov 14, 2000
Posts: 22
Dear Rama Krishna,

Thanks for your reply.

It works when i use the context.xml file in the META-INF
directory. But when i try to use by configering in the
server.xml and web.xml as per the tomcat document it doen't work.


Ganesh
Milan Jagatiya
Ranch Hand

Joined: Jan 01, 2007
Posts: 164
Hi, which version you are using?... if you are using 5.5.7 then put context.xml file in your web root's META-INF directory. and put following code


it works if your version is 5.5.7 enjoyyyyy.... milan. :thumb:


Milan.<br />I can because I think I can...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Connection pooling problem in Tomcat