Jacob Kjome wrote:
Hello Erik,
If you aren't using DBCP, then you can ignore all the stuff about the
driver needing to be in common/lib. The only reason it needs to be
there is for DBCP to have access to the driver.
As far as why, after a restart, it doesn't work in either place, I
have no idea. Sounds like an outside problem. See if you can connect
through a basic class outside the Tomcat container. If so, then try
it again in the container. That will rule out general database
connectivity issues.
Jake and everyone,
Sorry to have raised this question since it turned out it had nothing to
do with Tomcat, but if you're curious as to what it was, just in case
this "gotchas" someone else
First, actually it was because I want to migrate my app to use DBCP
instead of a home-rolled connection pool (as helpfully pointed out by
Hannes Schmidt yesterday) that I decided to ask my sysadmin to move the
MySQL driver from my webapp's WEB-INF/lib to $CATALINA_HOME/common/lib.
Because we use Gentoo Linux, and there happened to be a Gentoo ebuild
for the MySQL driver I wanted (2.0.14), he used that. I made the
mistake of thinking that this was simply an identical JAR file to the
one that MySQL distributes on their site, which I had been formerly using.
Unfortunately, it's not that simple. The MySQL driver package from the
ebuild has apparently been repackaged into the "org.gjt.mm.mysql"
package. I had never heard of GJT before so I checked it out --
apparently it's an effort to aggregate open source Java classes. But
because of the repackaging, the Class.forName() call needs to take into
account the different package name. So instead of
com.mysql.jdbc.Driver
I needed to use
org.gjt.mm.mysql.Driver
and it's as simple as that. I should have read the README distributed
with the ebuild instead of making the assumption that it was identical
to the MySQL-distributed driver. But just in case anyone ever runs into
this hiccup, I hope you find this explanation in the archives.
Erik
EP> Jacob Kjome wrote:
Hello Mehdi,
If you are using DBCP connection pooling, your driver *must* exist in
CATALINA_HOME/common/lib. This is because the DBCP libraries exist in
common/lib and the fact that classes from common/lib do not have
access to the child classloader in WEB-INF/lib. However, your classes
in WEB-INF/lib *does* have access to the parent classloader in
common/lib.
So, put it in common/lib and it should work.
dont' forget to add ?autoReconnect=true to your connection url config
for MySQL.
EP> After reading this a few days ago, I decided to ask my sysadmin to move
EP> my mysql-connector-java-2.0.14-bin.jar file from my webapp's WEB-INF/lib
EP> to $CATALINA_HOME/common/lib, and he did. After we restarted Tomcat, my
EP> webapp wouldn't work, so, to confirm that it wasn't an application-level
EP> problem, I put the mysql-connector-java-2.0.14-bin.jar file back in
EP> WEB-INF/lib (of my webapp). The driver still can't be found for some
EP> reason.
EP> Is there something that I'm supposed to do to "register" the driver?
EP> Does it change the JDBC url if you move it to common/lib for some reason?
EP> Erik
Jake
Wednesday, January 22, 2003, 9:13:39 AM, you wrote:
MNbc> Hello all,
MNbc> i have been breaking my brain trying to get connection pooling, using
MNbc> Tomcat 4.1.12's build in dbcp, with mySQL 3.23.
MNbc> I have followed the instructions on the how this should be done, and I am
MNbc> getting an exception when I try to get a connection .. (like many other
MNbc> people it seems).. If anyone has solved this problem.. or has a link to a
MNbc> forum where this problem is answered please let me know..
MNbc> I have downloaded mysql-connector-java-2.0.14.zip
MNbc> I unzipped it and copied :
MNbc> * the contents of WEB-INF/lib to my lib folder
MNbc> * contents of com to my WEB-INF/classes folder
MNbc> * contents of org to my WEB-INF/classes folder (this *does* contain
MNbc> org.gjt.mm.mysql.Driver)
MNbc> This does not work. My jsp test code follows, and the Exception occurs on
MNbc> getConnection()...
MNbc> <%@ page language="java" import="java.sql.*, javax.sql.*, javax.naming.*"
MNbc> errorPage="error.jsp" %>
MNbc> <%
MNbc> Context initContext = new InitialContext();
MNbc> Context envContext = (Context)initContext.lookup("java:/comp/env");
MNbc> DataSource ds = (DataSource)envContext.lookup("jdbc/mehdi");
MNbc> Connection conn = ds.getConnection();
%>>
MNbc> Exception is
MNbc> java.sql.SQLException: Cannot load JDBC driver class
MNbc> 'org.gjt.mm.mysql.Driver'
MNbc> SERVER.XML
MNbc>
MNbc>prefix="localhost_DBTest_log." suffix=".txt"
MNbc> timestamp="true"/>
MNbc> auth="Container"
MNbc>type="javax.sql.DataSource"/>
MNbc>
MNbc>
MNbc> factory
MNbc> org.apache.commons.dbcp.BasicDataSourceFactory
MNbc>
MNbc>
MNbc>
MN