You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Eugene Lee <li...@fsck.net> on 2003/08/23 14:49:45 UTC

mysql connection pooling problem

I'm having a really odd problem connecting to a local MySQL server.  If
I use java.sql.DriverManager.getConnection(), it works perfectly fine.
But when I try to use a connection pool:

	http://www.mysql.com/articles/connection_pooling_with_connectorj.html

it errors out:

	java.sql.SQLException: Cannot load JDBC driver class 'null'

I've tried moving the MySQL driver to $CATALINA_HOME/common/lib,
$JAVA_HOME/jre/lib/ext, and even my webapp's WEB-INF/lib.  The results
are still the same.

I've followed the often-recommended Tomcat 4.1 documentation to no avail.
Here's what my box is running:

	FreeBSD 4.8-RELEASE-p3                                   
	Java 2 SDK 1.3.1_09
	Jakarta-Tomcat 4.1.27
	MySQL Connector/J 3.0.8

I've attached my server.xml, my webapp's web.xml, and a test page
test.jsp to demonstrate the error.  BTW, before it throws the exception
on the getconnection(), the page output is:

	con1 works!
	DS lookup OK!

I appreciate any suggestions.  Much thanks in advance.


-- 
Eugene Lee
http://www.coxar.pwp.blueyonder.co.uk/

Re: mysql connection pooling problem

Posted by Eugene Lee <li...@fsck.net>.
On Tue, Aug 26, 2003 at 05:43:02AM -0400, Christopher Garrett wrote:
: 
: This is an absolute shot in the dark, but I believe you might have to
: put a JAR with JDBC drivers into WEB-INF/lib.

Hi Christopher,

Thanks for the suggestion.  But as I mentioned in my original message,
I already tried this to no avail... :-/


-- 
Eugene Lee
http://www.coxar.pwp.blueyonder.co.uk/

Re: mysql connection pooling problem

Posted by Christopher Garrett <mi...@inixoma.com>.
This is an absolute shot in the dark, but I believe you might have to put a JAR
with JDBC drivers into WEB-INF/lib.

Christopher Garrett III
Inixoma, Incorporated

----- Original Message -----
From: "Eugene Lee" <li...@fsck.net>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Monday, August 25, 2003 8:13 AM
Subject: Re: mysql connection pooling problem


Hi James,

I tried inserting the <context-param> into <web-app>, no effect.

But thanks for catching the typo in my JSP code in the lookup() line.
Unfortunately, this had no effect either.  I still get the infamous
"Cannot load JDBC driver class 'null'" error... hurmmm...

Any suggestions from others are appreciated too!  Anyone?


On Sat, Aug 23, 2003 at 11:09:36AM -0600, James Harman wrote:
: Eugene Lee wrote:
: >On Sat, Aug 23, 2003 at 08:59:05AM -0600, James Harman wrote:
: >:
: >: I noticed that in the web.xml you have the jbdc resource in a
: >: resource-ref.  In my stuff I have it as a context-param like this
: >:
: >: <context-param>
: >:    <param-name>
: >:      javax.servlet.jsp.jstl.sql.dataSource
: >:    </param-name>
: >:    <param-value>
: >:        jdbc/testdev
: >:    </param-value>
: >:  </context-param>
: >:
: >: This comes right after the <web-app> element in the web.xml file.
: >:
: >: I am not experienced enough to know the difference between context-param
: >: and resource-ref, but this seems to work for me.
:
: Another thing you might look at is your jsp code.  You have
:
: DataSource ds = (DataSource)ctx.lookup("java:/comp/env/jdbc/testdev");
:
: you probably want
:
: DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/testdev");
:
: notice that there is no / before comp.


--
Eugene Lee
http://www.coxar.pwp.blueyonder.co.uk/

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org



Re: mysql connection pooling problem

Posted by Eugene Lee <li...@fsck.net>.
Hi James,

I tried inserting the <context-param> into <web-app>, no effect.

But thanks for catching the typo in my JSP code in the lookup() line.
Unfortunately, this had no effect either.  I still get the infamous
"Cannot load JDBC driver class 'null'" error... hurmmm...

Any suggestions from others are appreciated too!  Anyone?


On Sat, Aug 23, 2003 at 11:09:36AM -0600, James Harman wrote:
: Eugene Lee wrote:
: >On Sat, Aug 23, 2003 at 08:59:05AM -0600, James Harman wrote:
: >: 
: >: I noticed that in the web.xml you have the jbdc resource in a 
: >: resource-ref.  In my stuff I have it as a context-param like this
: >: 
: >: <context-param>
: >:    <param-name>
: >:      javax.servlet.jsp.jstl.sql.dataSource
: >:    </param-name>
: >:    <param-value>
: >:        jdbc/testdev
: >:    </param-value>
: >:  </context-param>
: >: 
: >: This comes right after the <web-app> element in the web.xml file. 
: >: 
: >: I am not experienced enough to know the difference between context-param 
: >: and resource-ref, but this seems to work for me.
:
: Another thing you might look at is your jsp code.  You have
: 
: DataSource ds = (DataSource)ctx.lookup("java:/comp/env/jdbc/testdev");
: 
: you probably want
: 
: DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/testdev");
: 
: notice that there is no / before comp.


-- 
Eugene Lee
http://www.coxar.pwp.blueyonder.co.uk/

Re: mysql connection pooling problem

Posted by James Harman <ha...@comcast.net>.
Another thing you might look at is your jsp code.  You have

DataSource ds = (DataSource)ctx.lookup("java:/comp/env/jdbc/testdev");

you probably want

DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/testdev");


notice that there is no / before comp.

James


Eugene Lee wrote:

>On Sat, Aug 23, 2003 at 08:59:05AM -0600, James Harman wrote:
>: 
>: Eugene,
>: 
>: I noticed that in the web.xml you have the jbdc resource in a 
>: resource-ref.  In my stuff I have it as a context-param like this
>: 
>: <context-param>
>:    <param-name>
>:      javax.servlet.jsp.jstl.sql.dataSource
>:    </param-name>
>:    <param-value>
>:        jdbc/testdev
>:    </param-value>
>:  </context-param>
>: 
>: This comes right after the <web-app> element in the web.xml file. 
>: 
>: I am not experienced enough to know the difference between context-param 
>: and resource-ref, but this seems to work for me.
>
>I'm using <resource-ref> because that's what the Tomcat docs say.  :-)
>
>	http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html#MySQL%20DBCP%20Example
>
>I'll try it out later today and report back with the results.
>
>
>  
>


Re: mysql connection pooling problem

Posted by Eugene Lee <li...@fsck.net>.
On Sat, Aug 23, 2003 at 08:59:05AM -0600, James Harman wrote:
: 
: Eugene,
: 
: I noticed that in the web.xml you have the jbdc resource in a 
: resource-ref.  In my stuff I have it as a context-param like this
: 
: <context-param>
:    <param-name>
:      javax.servlet.jsp.jstl.sql.dataSource
:    </param-name>
:    <param-value>
:        jdbc/testdev
:    </param-value>
:  </context-param>
: 
: This comes right after the <web-app> element in the web.xml file. 
: 
: I am not experienced enough to know the difference between context-param 
: and resource-ref, but this seems to work for me.

I'm using <resource-ref> because that's what the Tomcat docs say.  :-)

	http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jndi-datasource-examples-howto.html#MySQL%20DBCP%20Example

I'll try it out later today and report back with the results.


-- 
Eugene Lee
http://www.coxar.pwp.blueyonder.co.uk/

Re: mysql connection pooling problem

Posted by James Harman <ha...@comcast.net>.
Eugene,

I noticed that in the web.xml you have the jbdc resource in a 
resource-ref.  In my stuff I have it as a context-param like this

 <context-param>
    <param-name>
      javax.servlet.jsp.jstl.sql.dataSource
    </param-name>
    <param-value>
        jdbc/testdev
    </param-value>
  </context-param>

This comes right after the <web-app> element in the web.xml file. 

I am not experienced enough to know the difference between context-param 
and resource-ref, but this seems to work for me.

James


Eugene Lee wrote:

>I'm having a really odd problem connecting to a local MySQL server.  If
>I use java.sql.DriverManager.getConnection(), it works perfectly fine.
>But when I try to use a connection pool:
>
>	http://www.mysql.com/articles/connection_pooling_with_connectorj.html
>
>it errors out:
>
>	java.sql.SQLException: Cannot load JDBC driver class 'null'
>
>I've tried moving the MySQL driver to $CATALINA_HOME/common/lib,
>$JAVA_HOME/jre/lib/ext, and even my webapp's WEB-INF/lib.  The results
>are still the same.
>
>I've followed the often-recommended Tomcat 4.1 documentation to no avail.
>Here's what my box is running:
>
>	FreeBSD 4.8-RELEASE-p3                                   
>	Java 2 SDK 1.3.1_09
>	Jakarta-Tomcat 4.1.27
>	MySQL Connector/J 3.0.8
>
>I've attached my server.xml, my webapp's web.xml, and a test page
>test.jsp to demonstrate the error.  BTW, before it throws the exception
>on the getconnection(), the page output is:
>
>	con1 works!
>	DS lookup OK!
>
>I appreciate any suggestions.  Much thanks in advance.
>
>
>  
>
>------------------------------------------------------------------------
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>


Re: mysql connection pooling problem

Posted by Eugene Lee <li...@fsck.net>.
On Tue, Aug 26, 2003 at 08:25:31AM -0600, Steve Wilkinson wrote:
: 
: I followed the example at 
: http://jakarta.apache.org/tomcat/tomcat-4.1-doc/printer/jndi-datasource-examples-howto.html#MySQL%20DBCP%20Example.
: 
: The only thing I see wrong is the following line of code:
: 
: DataSource ds = (DataSource)ctx.lookup("java:/comp/env/jdbc/testdev")
: 
: should be "java:comp/env/jdbc/testdev" as already mentioned earlier.

Thanks Steve.  An earlier response mentioned the same typo, and I've
already fixed it.  But I still get the same error message.

: Thus, I've attached my example for you to compare.  Note, DBCP 
: connection pool requires additional jars as indicated in the README.txt 
: file.  I assume you already know this, but I mention it just incase.

Yep, I've got all those JARs in $CATALINA_HOME/common/lib.


-- 
Eugene Lee
http://www.coxar.pwp.blueyonder.co.uk/

Re: mysql connection pooling problem

Posted by Steve Wilkinson <ws...@forethought.net>.
Eugene,

I followed the example at 
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/printer/jndi-datasource-examples-howto.html#MySQL%20DBCP%20Example.

The only thing I see wrong is the following line of code:

DataSource ds = (DataSource)ctx.lookup("java:/comp/env/jdbc/testdev")

should be "java:comp/env/jdbc/testdev" as already mentioned earlier.

Thus, I've attached my example for you to compare.  Note, DBCP 
connection pool requires additional jars as indicated in the README.txt 
file.  I assume you already know this, but I mention it just incase.

Hope this helps,

Steve


Eugene Lee wrote:

> I'm having a really odd problem connecting to a local MySQL server.  If
> I use java.sql.DriverManager.getConnection(), it works perfectly fine.
> But when I try to use a connection pool:
> 
> 	http://www.mysql.com/articles/connection_pooling_with_connectorj.html
> 
> it errors out:
> 
> 	java.sql.SQLException: Cannot load JDBC driver class 'null'
> 
> I've tried moving the MySQL driver to $CATALINA_HOME/common/lib,
> $JAVA_HOME/jre/lib/ext, and even my webapp's WEB-INF/lib.  The results
> are still the same.
> 
> I've followed the often-recommended Tomcat 4.1 documentation to no avail.
> Here's what my box is running:
> 
> 	FreeBSD 4.8-RELEASE-p3                                   
> 	Java 2 SDK 1.3.1_09
> 	Jakarta-Tomcat 4.1.27
> 	MySQL Connector/J 3.0.8
> 
> I've attached my server.xml, my webapp's web.xml, and a test page
> test.jsp to demonstrate the error.  BTW, before it throws the exception
> on the getconnection(), the page output is:
> 
> 	con1 works!
> 	DS lookup OK!
> 
> I appreciate any suggestions.  Much thanks in advance.
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> <Server port="8005" shutdown="SHUTDOWN" debug="0">
> 
>   <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"
>             debug="0"/>
>   <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
>             debug="0"/>
> 
>   <!-- Global JNDI resources -->
>   <GlobalNamingResources>
> 
>     <!-- Editable user database that can also be used by
>          UserDatabaseRealm to authenticate users -->
>     <Resource name="UserDatabase" auth="Container"
>               type="org.apache.catalina.UserDatabase"
>               description="User database that can be updated and saved">
>     </Resource>
>     <ResourceParams name="UserDatabase">
>       <parameter>
>         <name>factory</name>
>         <value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
>       </parameter>
>       <parameter>
>         <name>pathname</name>
>         <value>conf/tomcat-users.xml</value>
>       </parameter>
>     </ResourceParams>
> 
>   </GlobalNamingResources>
> 
>   <Service name="Tomcat-Apache">
> 
>     <Connector className="org.apache.catalina.connector.warp.WarpConnector"
>                port="8008" minProcessors="5" maxProcessors="75"
>                enableLookups="true" appBase="webapps" acceptCount="10"
>                debug="0"/>
> 
>     <Engine className="org.apache.catalina.connector.warp.WarpEngine"
>             name="Apache" debug="0">
> 
>     <Logger className="org.apache.catalina.logger.FileLogger"
>             prefix="catalina_log." suffix=".txt" timestamp="true"/>
> 
>     <Host name="localhost" debug="0" appBase="webapps"
>           unpackWARs="true" autoDeploy="true">
> 
>       <Logger className="org.apache.catalina.logger.FileLogger"
>               directory="logs"  prefix="localhost_log." suffix=".txt"
>               timestamp="true"/>
> 
>       <Context path="/testdev" docBase="testdev" debug="0" reloadable="true"
>                crossContext="true">
>         <Logger className="org.apache.catalina.logger.FileLogger"
>                 prefix="testdev_log." suffix=".txt"
>                 timestamp="true"/>
>         <Resource name="jdbc/testdev" auth="Container"
>                   type="javax.sql.DataSource"/>
>         <ResourceParams name="jdbc/testdev">
>           <parameter>
>             <name>factory</name>
>             <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
>           </parameter>
>           <parameter>
>             <name>maxActive</name>
>             <value>500</value>
>           </parameter>
>           <parameter>
>             <name>maxIdle</name>
>             <value>500</value>
>           </parameter>
>           <parameter>
>             <name>maxWait</name>
>             <value>10000</value>
>           </parameter>
>           <parameter>
>             <name>username</name>
>             <value>********</value>
>           </parameter>
>           <parameter>
>             <name>password</name>
>             <value>********</value>
>           </parameter>
>           <parameter>
>             <name>driverClassName</name>
>             <value>com.mysql.jdbc.Driver</value>
>           </parameter>
>           <parameter>
>             <name>url</name>
>             <value>jdbc:mysql://localhost/testdev</value>
>           </parameter>
>         </ResourceParams>
>       </Context>
> 
>     </Host>
> 
>     <Realm className="org.apache.catalina.realm.MemoryRealm" />
> 
>     </Engine>
> 
>   </Service>
> 
> </Server>
> 
> 
> ------------------------------------------------------------------------
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
> <web-app id="TESTDEV">
>     <display-name>testdev</display-name>
>     <servlet>
>         <servlet-name>action</servlet-name>
>         <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
>         <init-param>
>             <param-name>config</param-name>
>             <param-value>WEB-INF/struts-config.xml</param-value>
>         </init-param>
>         <init-param>
>             <param-name>application</param-name>
>             <param-value>resource</param-value>
>         </init-param>
>         <init-param>
>             <param-name>debug</param-name>
>             <param-value>2</param-value>
>         </init-param>
>         <init-param>
>             <param-name>detail</param-name>
>             <param-value>2</param-value>
>         </init-param>
>         <init-param>
>             <param-name>validate</param-name>
>             <param-value>true</param-value>
>         </init-param>
>         <load-on-startup>2</load-on-startup>
>     </servlet>
>     <servlet-mapping>
>         <servlet-name>action</servlet-name>
>         <url-pattern>*.do</url-pattern>
>     </servlet-mapping>
>     <welcome-file-list>
>         <welcome-file>index.html</welcome-file>
>         <welcome-file>index.htm</welcome-file>
>         <welcome-file>index.jsp</welcome-file>
>         <welcome-file>default.html</welcome-file>
>         <welcome-file>default.htm</welcome-file>
>         <welcome-file>default.jsp</welcome-file>
>     </welcome-file-list>
>     <taglib>
>         <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
>         <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
>     </taglib>
>     <taglib>
>         <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
>         <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
>     </taglib>
>     <taglib>
>         <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
>         <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
>     </taglib>
>     <taglib>
>         <taglib-uri>/WEB-INF/struts-template.tld</taglib-uri>
>         <taglib-location>/WEB-INF/struts-template.tld</taglib-location>
>     </taglib>
>     <taglib>
>         <taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri>
>         <taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
>     </taglib>
>     <taglib>
>         <taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
>         <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
>     </taglib>
>     <taglib>
>         <taglib-uri>http://jakarta.apache.org/taglibs/application-1.0</taglib-uri>
>         <taglib-location>/WEB-INF/lib/application.jar</taglib-location>
>     </taglib>
>     <taglib>
>         <taglib-uri>http://jakarta.apache.org/taglibs/page-1.0</taglib-uri>
>         <taglib-location>/WEB-INF/lib/page.jar</taglib-location>
>     </taglib>
>     <taglib>
>         <taglib-uri>http://jakarta.apache.org/taglibs/request-1.0</taglib-uri>
>         <taglib-location>/WEB-INF/lib/request.jar</taglib-location>
>     </taglib>
>     <taglib>
>         <taglib-uri>http://jakarta.apache.org/taglibs/response-1.0</taglib-uri>
>         <taglib-location>/WEB-INF/lib/response.jar</taglib-location>
>     </taglib>
>     <taglib>
>         <taglib-uri>http://jakarta.apache.org/taglibs/session-1.0</taglib-uri>
>         <taglib-location>/WEB-INF/lib/session.jar</taglib-location>
>     </taglib>
>     <taglib>
>         <taglib-uri>jspsql</taglib-uri>
>         <taglib-location>/WEB-INF/lib/jspsql.jar</taglib-location>
>     </taglib>
>     <taglib>
>         <taglib-uri>http://jakarta.apache.org/taglibs/i18n-1.0</taglib-uri>
>         <taglib-location>/WEB-INF/lib/i18n.jar</taglib-location>
>     </taglib>
>     <taglib>
>         <taglib-uri>http://jakarta.apache.org/taglibs/datetime-1.0</taglib-uri>
>         <taglib-location>/WEB-INF/lib/datetime.jar</taglib-location>
>     </taglib>
>     <taglib>
>         <taglib-uri>http://jakarta.apache.org/taglibs/string-1.0</taglib-uri>
>         <taglib-location>/WEB-INF/lib/string.jar</taglib-location>
>     </taglib>
>     <taglib>
>         <taglib-uri>http://jakarta.apache.org/taglibs/utility</taglib-uri>
>         <taglib-location>/WEB-INF/lib/utility.jar</taglib-location>
>     </taglib>
>     <taglib>
>         <taglib-uri>http://jakarta.apache.org/taglibs/mailer-1.0</taglib-uri>
>         <taglib-location>/WEB-INF/lib/mailer.jar</taglib-location>
>     </taglib>
> 
>     <resource-ref>
>         <description>DB Connection</description>
>         <res-ref-name>jdbc/testdev</res-ref-name>
>         <res-type>javax.sql.DataSource</res-type>
>         <res-auth>Container</res-auth>
>     </resource-ref>
> 
> </web-app>
> 
> 
> ------------------------------------------------------------------------
> 
> <%@ page import="javax.sql.DataSource" %>
> <%@ page import="javax.naming.Context" %>
> <%@ page import="javax.naming.InitialContext" %>
> <%@ page import="java.sql.*" %>
> <html>
>     <head><title>my test</title></head>
> <body>
> <%
> 
> try
> {
>     Class.forName("com.mysql.jdbc.Driver").newInstance();
>     Connection con1 = java.sql.DriverManager.getConnection("jdbc:mysql://localhost/testdev?user=********&password=********");
>     con1.close();
>     out.println("con1 works!");
> }
> catch(Exception e)
> {
>     System.out.println(e);
> }
> 
> try
> {
>     Context ctx = new InitialContext();
>     DataSource ds = (DataSource)ctx.lookup("java:/comp/env/jdbc/testdev");
>     out.println("<br>\nDS lookup OK!");
>     Connection con2 = ds.getConnection();
>     out.println("<br>\ncon2 getConnection OK!");
>     con2.close();
> }
> catch(Exception e)
> {
>     System.out.println(e);
> }
> %>
> 
> </body>
> </html>
> 
> 
> ------------------------------------------------------------------------
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org