Jacob Kjome wrote:
Jake and everyone,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.
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> <Context path="/mysql" docBase="mysql" debug="0" reloadable="true"> MNbc> <Logger className="org.apache.catalina.logger.FileLogger" MNbc> prefix="localhost_DBTest_log." suffix=".txt" MNbc> timestamp="true"/> MNbc> <Resource name="jdbc/mehdi" MNbc> auth="Container" MNbc> type="javax.sql.DataSource"/> MNbc> <ResourceParams name="jdbc/mehdi"> MNbc> <parameter> MNbc> <name>factory</name> MNbc> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value> MNbc> </parameter> MNbc> <!-- Maximum number of dB connections in pool. Make sure you MNbc> configure your mysqld max_connections large enough to handle MNbc> all of your db connections. Set to 0 for no limit. MNbc> --> MNbc> <parameter> MNbc> <name>maxActive</name> MNbc> <value>100</value> MNbc> </parameter> MNbc> <!-- Maximum number of idle dB connections to retain in pool. MNbc> Set to 0 for no limit. MNbc> --> MNbc> <parameter> MNbc> <name>maxIdle</name> MNbc> <value>30</value> MNbc> </parameter> MNbc> <!-- Maximum time to wait for a dB connection to become available MNbc> in ms, in this example 10 seconds. An Exception is thrown if MNbc> this timeout is exceeded. Set to -1 to wait indefinitely. MNbc> --> MNbc> <parameter> MNbc> <name>maxWait</name> MNbc> <value>10000</value> MNbc> </parameter> MNbc> <!-- MySQL dB username and password for dB connections --> MNbc> <parameter> MNbc> <name>username</name> MNbc> <value>mehdi</value> MNbc> </parameter> MNbc> <parameter> MNbc> <name>password</name> MNbc> <value>mypass</value> MNbc> </parameter> MNbc> <!-- Class name for mm.mysql JDBC driver --> MNbc> <parameter> MNbc> <name>driverClassName</name> MNbc> <value>org.gjt.mm.mysql.Driver</value> MNbc> </parameter> MNbc> <!-- The JDBC connection url for connecting to your MySQL dB. MNbc> The autoReconnect=true argument to the url makes sure that the MNbc> mm.mysql JDBC Driver will automatically reconnect if mysqld closed MNbc> the MNbc> connection. mysqld by default closes idle connections after 8 MNbc> hours. MNbc> --> MNbc> <parameter> MNbc> <name>url</name> MNbc> <value>jdbc:mysql://localhost:3306/mehdi?autoReconnect=true</value> MNbc> </parameter> MNbc> </ResourceParams> MNbc> </Context> MNbc> running out of time, and hair. MNbc> Thanks, MNbc> Med MNbc> -- MNbc> To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> MNbc> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>EP> --------------------------------------------------------------------- EP> To unsubscribe, e-mail: [EMAIL PROTECTED] EP> For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]