# Trouble with Tomcat 5.5 and MySQL

## nejiron

I recently upgraded to Tomcat 5.5 and Java 1.5 and then emerged -e world again to compile everything with the new java compiler, and Tomcat is no longer working with mysql.

I keep getting the following error:

 *Quote:*   

> 
> 
> type Exception report
> 
> message
> ...

 

Despite having followed Apache's website on how to set up JDBC perfectly.  I had it working for Tomcat 5.0 also.  The JDBC-mysql jar files are everywhere in common/lib, WEB-INF/lib, etc..  Heres what my context file looks like:

```

<Context path="/DBTest" docBase="${catalina.home}/server/webapps/DBTest"

        debug="5" reloadable="true" crossContext="true">

  <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?autoReconnect=true"/>

</Context>

```

at /etc/tomcat-5.5/Catalina/localhost/DBTest.xml

and this is what my JSP file looks like that craps out when I try and load it:

```

<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<sql:query var="rs" dataSource="jdbc/TestDB">

select id, foo, bar from testdata

</sql:query>

<html>

  <head>

    <title>DB Test</title>

  </head>

  <body>

  <h2>Results</h2>

<c:forEach var="row" items="${rs.rows}">

    Foo ${row.foo}<br/>

    Bar ${row.bar}<br/>

</c:forEach>

  </body>

</html>

```

located at /usr/share/tomcat-5.5/server/webapps/DBTest

with a web.xml file that looks like this:

```

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee

http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"

    version="2.4">

  <description>MySQL Test App</description>

  <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>

</web-app>

```

at /usr/share/tomcat-5.5/server/webapps/DBTest/WEB-INF

Any help would be appreciated.

----------

## linear

Not using tomcat 5.5 or java 1.5 but have torn hair out on resources and tomcat many times.

Is your driver on your classpath?

Here is a quick JSP page for displaying your CLASSPATH variable in the servers context:

#vi viewclasspath.jsp

```
<%

  Object o =  getServletContext().getAttribute("org.apache.catalina.jsp_classpath");

%>

<%= o.toString().replaceAll(":","<BR>") %>

```

The connector should be in the ${CATALINA_HOME}/common/lib directory ONLY.  If it is multiple locations you can run into conflicts.

If it is in the CLASSPATH.  It may be that the old Class file is incompatable with the changes in 1.5 (dunno, but I do know that there are major changes in the language spec with 1.5 and while people try to be backwards compatable... wel... you know...)  Maybe there is a newer version of the driver?

I use org.gjt.mm.mysql.Driver in /usr/share/tomcat-5/common/lib/mysql-connector-java-3.0.16-ga-bin.jar but am using tomcat 5.0.28 and mysql 4.0

Hope it helps

----------

## nejiron

Results

/usr/share/tomcat-5.5/server/webapps/DBTest/WEB-INF/classes/

/var/lib/tomcat-5.5/shared/classes/

/usr/share/tomcat-5.5/common/i18n/tomcat-i18n-en.jar

/usr/share/tomcat-5.5/common/i18n/tomcat-i18n-es.jar

/usr/share/tomcat-5.5/common/i18n/tomcat-i18n-fr.jar

/usr/share/tomcat-5.5/common/i18n/tomcat-i18n-ja.jar

/usr/share/xerces-2/lib/xercesImpl.jar

/usr/share/xerces-2/lib/xml-apis.jar

/usr/share/commons-collections/lib/commons-collections.jar

/usr/share/commons-pool/lib/commons-pool.jar

/usr/share/tomcat-5.5/lib/jasper-compiler.jar

/usr/share/tomcat-5.5/common/lib/jstl.jar

/usr/share/servletapi-2.4/lib/servlet-api.jar

/usr/share/commons-el/lib/commons-el.jar

/usr/share/tomcat-5.5/lib/naming-factory.jar

/usr/share/tomcat-5.5/common/lib/standard.jar

/usr/share/tomcat-5.5/lib/jasper-runtime.jar

/usr/share/servletapi-2.4/lib/jsp-api.jar

/usr/share/tomcat-5.5/lib/naming-resources.jar

/usr/share/ant-core/lib/ant.jar

/usr/share/tomcat-5.5/common/lib/jdbc-mysql.jar

/usr/share/ant-core/lib/ant-launcher.jar

/usr/share/commons-dbcp/lib/commons-dbcp.jar

/usr/share/tomcat-5.5/server/lib/

/opt/sun-jdk-1.5.0.07/lib/tools.jar

/usr/share/tomcat-5.5/bin/bootstrap.jar

/usr/share/commons-logging/lib/commons-logging.jar

/usr/share/commons-logging/lib/commons-logging-api.jar

/opt/sun-jdk-1.5.0.07/jre/lib/ext/dnsns.jar

/opt/sun-jdk-1.5.0.07/jre/lib/ext/sunpkcs11.jar

/opt/sun-jdk-1.5.0.07/jre/lib/ext/sunjce_provider.jar

/opt/sun-jdk-1.5.0.07/jre/lib/ext/localedata.jar 

It's in the class path, should work.  Need to try some more things.

----------

## rojanu

Hi!

I have made a web app and deployed it. Application uses mysql but for some reason after sime time it just needs a restart

of the tomcat server to be able to connect to the database again.  Do you think the problem is caused by the same thing.

Any ideas?

Thanks

----------

## nejiron

not sure what your problem is caused by, I managed to fix mine though by fiddling around with configuration files...

----------

## akbarstatx

I was having the same problems too,  but then I noticed this in my catalina error log

```

Aug 28, 2006 1:35:53 AM org.apache.catalina.core.NamingContextListener addResource

WARNING: Failed to register in JMX: javax.naming.NamingException: Could not create resource factory instance [Root exception is java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory]

```

I had to add namingfactory-dbcp.jar to tomcat-5.5/common/lib directory.  This jar is in the tar ball from apache.org but it is not in added by portage's ebuild for tomcat.  I think this is a bug in the ebuild for tomcat.

----------

## wltjr

Please see bug 144276 this is a known problem and issue. Still working on a solution.

----------

