Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connection pooling problem in Tomcat

 
Ganesh Chandrasekaran
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ganesh Chandrasekaran
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic