tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Smith <d...@cornell.edu>
Subject Re: Datasource: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
Date Sun, 16 Sep 2007 15:39:20 GMT
Don't 'copy' the mysql driver from WEB-INF/lib to TOMCAT_HOME/common/lib 
-- move it.  It cannot be in both places at once.  Also be sure the 
permissions are set correctly so tomcat can read the jar and be sure 
you've restarted tomcat after the move so the classloaders pick it up 
properly.  I have no idea why it works in Windows at all unless the 
Windows install has a copy of it in common/lib already -- which can 
cause problems later on if it's also in WEB-INF/lib.

As a side note (and this is becoming a mantra with me) please don't use 
?autoReconnect=true in your jdbc url.  Instead add the attribute 
validationQuery="select 1" in the Resource element.  That tells the pool 
how to validate the connection and optionally regenerate it before you 
borrow.

--David

Ken Bowen wrote:
> Hello,
>
> I'm working on a CENTOS 5 Linux setup.
> I'm trying to avoid the pre-loaded tomcat which was installed in 
> /usr/share/tomcat5.
> I downloaded (from apache) and installed tomcat5.5.25 and installed it 
> in /opt/tomcat5.
> I made sure the existing tomcat is not running and I renamed 
> /usr/share/tomcat5.
>
> I start it (the new tomcat) with /opt/tomcat5/bin/startup.sh and it 
> runs fine:
> Tomcat manager runs and I can start/stop the built-in apps.
>
> I have an app which I developed using tomcat5.5.9 on Windows, and I am 
> trying to
> transfer it to this Linux setting.
>
> I placed my exploded app in webapps.  The app wants to use a Mysql 
> database named sb_data.
> The same database as on Windows has been replicated in Mysql in the 
> Linux setup.
> I have the following context.xml in my META-INF folder:
>
>    <Context path="/myapp" docBase="myapp"
>                      debug="5" reloadable="true" crossContext="true">
>       <Resource name="jdbc/sb_data" auth="Container"
>    type="javax.sql.DataSource"
>                 maxActive="100" maxIdle="30" maxWait="10000"
>                 username="sb_normal" password="********"
>                 driverClassName="com.mysql.jdbc.Driver"
>                   
> url="jdbc:mysql://localhost:3306/sb_data?autoReconnect=true"/>
>    </Context>
>
> My application has a registered AppListener in which I establish the 
> DataSource
> in the contextInitialized method and use it to do some initial work 
> with the database:
>
>        System.out.println("MyApp AppListener: ENTER");
>        ....
>        Context envCtx = (Context) initialContext.lookup("java:comp/env");
>
>        String key = "jdbc" + "/" + "sb_data";
>        DataSource ds = (DataSource)envCtx.lookup(key);
>        if (ds != null ){
>            DAOBaseData.setDataSource(ds);
>        }
>        ....
>        ...CALL to DAOBaseData.getConnection();  HERE
>        ....
>        System.out.println("MyApp AppListener: EXIT");
>
> The code for getConnection() looks like this:
>
>        public Connection getConnection() throws DAOException
>        {
>            Connection connection = null;
>            if (datasource!= null) {
>                try {
>                    connection = datasource.getConnection();
>                } catch (SQLException e) {
>                      //TODO: Log this
>                      String message = e.getMessage();
>                      System.out.println("DAOBaseData: "+message);
>                      throw new DAOException(message);
>                }
>            }
>            connCount++;
>            System.out.println("Connection[data] allocated: 
> #="+connCount);
>            return connection;
>        }
>
> This works ok on Windows, but in the Linux setting I get the following 
> error in
> the catalina.out log:
>
>        MyApp AppListener: ENTER
>        DAOBaseData: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
>        com.myapp Error: Cannot load JDBC driver class
>    'com.mysql.jdbc.Driver'
>        MyApp AppListener: EXIT
>
> I'm using the mysql-connector-java-3.1.14-bin.jar and it is present in 
> WEB-INF/lib.
> I tried copying it to /opt/tomcat5/common/lib , but I still get the 
> same error.
>
> I'm confused.  Why does tomcat on Windows find the JDBC driver, but 
> not find it on Linux?
>
> Thanks in advance,
> Ken Bowen
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message