Discussion:
java.sql.SQLException: No suitable driver found for in tomcat 6.0.35, is the class loading changed?
Frank Zhang
2011-12-17 00:49:46 UTC
Permalink
Hi All:
Our code is using apache dbcp library and mysql-connector as JDBC driver other than tomcat own tomcat-dbcp.jar. we always put mysql-connector at CATALINA_HOME/lib while put commons-dbcp-1.4.jar
at CATALINA_HOME/webapps/client/WEB-INF/lib/. This worked fairly well in tomcat 6.0.2x and even in 6.0.33. In 6.0.35 I encountered the error "java.sql.SQLException: No suitable driver found for" during the booting time which looks like mysql-connector not in classpath. Considering it's working all right before, my suspect is 6.0.35 silently changed its class loading way. Could somebody give me some hints? Thanks.

Accidentally, I tried putting mysql-connector to CATALINA_HOME/webapps/client/WEB-INF/lib/, but no better result.

--------------- the error ----------------

[java] java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/cloud?autoReconnect=true&prepStmtCacheSize=517&cachePrepStmts=true
[java] at java.sql.DriverManager.getConnection(DriverManager.java:640)
[java] at java.sql.DriverManager.getConnection(DriverManager.java:200)
[java] at org.apache.commons.dbcp.DriverManagerConnectionFactory.createConnection(DriverManagerConnectionFactory.java:75)
[java] at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
[java] at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1181)
[java] at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106)
[java] at com.cloud.utils.db.Transaction.getStandaloneConnectionWithException(Transaction.java:199)
[java] at com.cloud.utils.db.Transaction.getStandaloneConnection(Transaction.java:208)
[java] at com.cloud.utils.db.DbUtil.getConnectionForGlobalLocks(DbUtil.java:59)
[java] at com.cloud.utils.db.DbUtil.getGlobalLock(DbUtil.java:204)
[java] at com.cloud.utils.db.GlobalLock.lock(GlobalLock.java:153)
[java] at com.cloud.upgrade.DatabaseIntegrityChecker.check(DatabaseIntegrityChecker.java:208)
[java] at com.cloud.utils.component.ComponentLocator.runCheckers(ComponentLocator.java:240)
[java] at com.cloud.utils.component.ComponentLocator.parse(ComponentLocator.java:211)
[java] at com.cloud.utils.component.ComponentLocator.getLocatorInternal(ComponentLocator.java:795)
[java] at com.cloud.utils.component.ComponentLocator.getLocator(ComponentLocator.java:833)
[java] at com.cloud.utils.component.ComponentLocator.getComponent(ComponentLocator.java:383)
[java] at com.cloud.utils.component.ComponentLocator.getComponent(ComponentLocator.java:376)
[java] at com.cloud.servlet.CloudStartupServlet.init(CloudStartupServlet.java:46)
[java] at javax.servlet.GenericServlet.init(GenericServlet.java:212)
[java] at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1206)
[java] at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1026)
[java] at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421)
[java] at org.apache.catalina.core.StandardContext.start(StandardContext.java:4734)
[java] at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
[java] at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
[java] at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
[java] at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
[java] at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
[java] at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
[java] at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
[java] at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
[java] at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
[java] at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
[java] at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
[java] at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
[java] at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
[java] at org.apache.catalina.core.StandardService.start(StandardService.java:525)
[java] at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
[java] at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[java] at java.lang.reflect.Method.invoke(Method.java:616)
[java] at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
[java] at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Christopher Schultz
2011-12-22 23:06:19 UTC
Permalink
Frank,
Post by Frank Zhang
Our code is using apache dbcp library and mysql-connector as JDBC
driver other than tomcat own tomcat-dbcp.jar.
Are you attempting to use the classes in tomcat-dbcp.jar directly? Or,
do you just mean that you are using a JNDI DataSource set up in your
<Context> element, and so Tomcat is using tomcat-dbcp.jar?
Post by Frank Zhang
we always put mysql-connector at CATALINA_HOME/lib
Good, if you are letting Tomcat configure your DataSource.
Post by Frank Zhang
while put commons-dbcp-1.4.jar at
CATALINA_HOME/webapps/client/WEB-INF/lib/.
Well, if you expect to use commons-dbcp directly, then this is
probably what you should do. If you are just using Tomcat's JNDI
DataSource, then you don't need this library anywhere at all.
Post by Frank Zhang
This worked fairly well in tomcat 6.0.2x and even in 6.0.33. In
6.0.35 I encountered the error "java.sql.SQLException: No suitable
driver found for" during the booting time which looks like
mysql-connector not in classpath.
CATALINA_HOME/lib will be in the CLASSPATH for Tomcat's ClassLoader,
which will be used after your webapp's ClassLoader, depending on
exactly when the driver tries to load.
Post by Frank Zhang
Considering it's working all right before, my suspect is 6.0.35
silently changed its class loading way. Could somebody give me
some hints? Thanks.
I suspect nothing has changed in Tomcat.
Post by Frank Zhang
Accidentally, I tried putting mysql-connector to
CATALINA_HOME/webapps/client/WEB-INF/lib/, but no better result.
If you are using a JNDI DataSource, you should probably have it in
CATALINA_HOME/lib and nowhere else.
Post by Frank Zhang
[java] java.sql.SQLException: No suitable driver found for
jdbc:mysql://localhost:3306/cloud?autoReconnect=true&prepStmtCacheSize=517&cachePrepStmts=true
[java] at java.sql.DriverManager.getConnection(DriverManager.java:640)
Post by Frank Zhang
[java] at
java.sql.DriverManager.getConnection(DriverManager.java:200) [java]
at
org.apache.commons.dbcp.DriverManagerConnectionFactory.createConnection(DriverManagerConnectionFactory.java:75)
[java] at
org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
Post by Frank Zhang
[java] at
org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1181)
[java] at
org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106)
Post by Frank Zhang
[java] at
com.cloud.utils.db.Transaction.getStandaloneConnectionWithException(Transaction.java:199)
So,
that looks like you are NOT using a Tomcat-created JNDI
DataSource, but instead using commons-dbcp directly. I don't think you
are using tomat-dbcp.jar at all, since those aren't the right class names.

Given that, I would expect you to put both the driver *and*
commons-dbcp.jar into your webapp's WEB-INF/lib directory. Make sure
that neither of those JAR files are also found in CATALINA_HOME/lib.

Can you re-confirm your current setup?

- -chris
Konstantin Kolinko
2011-12-25 08:23:50 UTC
Permalink
               Our code is using apache dbcp library and mysql-connector as JDBC driver other than tomcat own tomcat-dbcp.jar. we always put mysql-connector at CATALINA_HOME/lib while put commons-dbcp-1.4.jar
at CATALINA_HOME/webapps/client/WEB-INF/lib/. This worked fairly well in tomcat 6.0.2x and even in 6.0.33.  In 6.0.35 I encountered the error "java.sql.SQLException: No suitable driver found for" during the booting time which looks like mysql-connector not in classpath.  Considering it's working all right before, my suspect is 6.0.35 silently changed its class loading way. Could somebody give me some hints? Thanks.
Accidentally, I tried putting mysql-connector to CATALINA_HOME/webapps/client/WEB-INF/lib/,  but no better result.
--------------- the error ----------------
 [java] java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/cloud?autoReconnect=true&prepStmtCacheSize=517&cachePrepStmts=true
    [java]     at java.sql.DriverManager.getConnection(DriverManager.java:640)
    [java]     at java.sql.DriverManager.getConnection(DriverManager.java:200)
    [java]     at org.apache.commons.dbcp.DriverManagerConnectionFactory.createConnection(DriverManagerConnectionFactory.java:75)
    [java]     at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
    [java]     at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1181)
    [java]     at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106)
    [java]     at com.cloud.utils.db.Transaction.getStandaloneConnectionWithException(Transaction.java:199)
    [java]     at com.cloud.utils.db.Transaction.getStandaloneConnection(Transaction.java:208)
    [java]     at com.cloud.utils.db.DbUtil.getConnectionForGlobalLocks(DbUtil.java:59)
    [java]     at com.cloud.utils.db.DbUtil.getGlobalLock(DbUtil.java:204)
    [java]     at com.cloud.utils.db.GlobalLock.lock(GlobalLock.java:153)
    [java]     at com.cloud.upgrade.DatabaseIntegrityChecker.check(DatabaseIntegrityChecker.java:208)
    [java]     at com.cloud.utils.component.ComponentLocator.runCheckers(ComponentLocator.java:240)
    [java]     at com.cloud.utils.component.ComponentLocator.parse(ComponentLocator.java:211)
    [java]     at com.cloud.utils.component.ComponentLocator.getLocatorInternal(ComponentLocator.java:795)
    [java]     at com.cloud.utils.component.ComponentLocator.getLocator(ComponentLocator.java:833)
    [java]     at com.cloud.utils.component.ComponentLocator.getComponent(ComponentLocator.java:383)
    [java]     at com.cloud.utils.component.ComponentLocator.getComponent(ComponentLocator.java:376)
    [java]     at com.cloud.servlet.CloudStartupServlet.init(CloudStartupServlet.java:46)
    [java]     at javax.servlet.GenericServlet.init(GenericServlet.java:212)
There was
<add>
<bug>51640</bug>: Improve the memory leak prevention for leaks
triggered by java.sql.DriverManager. (markt/kkolinko)
</add>

The same code is in 7.0.21+, so IIRC similar issues were already discussed once.

Best regards,
Konstantin Kolinko
Florian Desbois
2012-02-08 15:06:20 UTC
Permalink
Hello,

I have the same issue with c3p0 0.9.1.2. Even if i put the mysql-connector
inside the webapp (instead of CATALINA_HOME/lib), the issue appears.

I also tried to put both c3p0 and mysql-connector in CATALINA_HOME/lib but
the same problem occurs. There is no issue when using tomcat 6.0.33.

I notice that using JNDI is a best practice, but it's a little bit of work
to do it now (lots of projects). Do you have any idea, why it doesn't work
anylonger ?

--- stackTrace ---

8 févr. 2012 15:58:37
com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run
ATTENTION:
com.mchange.v2.async.ThreadPoolAsynchronousRunner$***@c77d0d6
-- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending
tasks!
8 févr. 2012 15:58:37
com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run
ATTENTION:
com.mchange.v2.async.ThreadPoolAsynchronousRunner$***@c77d0d6
-- APPARENT DEADLOCK!!! Complete Status:
Managed Threads: 3
Active Threads: 3
Active Tasks:
com.mchange.v2.resourcepool.BasicResourcePool$***@7423c7f5
(com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
com.mchange.v2.resourcepool.BasicResourcePool$***@591ce164
(com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)
com.mchange.v2.resourcepool.BasicResourcePool$***@771199f0
(com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)
Pending Tasks:
com.mchange.v2.resourcepool.BasicResourcePool$***@249198a2
com.mchange.v2.resourcepool.BasicResourcePool$***@52bbc66f
com.mchange.v2.resourcepool.BasicResourcePool$***@25e0cbd8
com.mchange.v2.resourcepool.BasicResourcePool$***@4966e555
com.mchange.v2.resourcepool.BasicResourcePool$***@25a5519
com.mchange.v2.resourcepool.BasicResourcePool$***@7888dd83
com.mchange.v2.resourcepool.BasicResourcePool$***@61870147
com.mchange.v2.resourcepool.BasicResourcePool$***@66650e56
com.mchange.v2.resourcepool.BasicResourcePool$***@7490649e
com.mchange.v2.resourcepool.BasicResourcePool$***@33bdfcdb
com.mchange.v2.resourcepool.BasicResourcePool$***@7e23a866
com.mchange.v2.resourcepool.BasicResourcePool$***@5705013c
com.mchange.v2.resourcepool.BasicResourcePool$***@99436c6
com.mchange.v2.resourcepool.BasicResourcePool$***@61980613
com.mchange.v2.resourcepool.BasicResourcePool$***@43b6fb73
com.mchange.v2.resourcepool.BasicResourcePool$***@22365dc0
com.mchange.v2.resourcepool.BasicResourcePool$***@1f44f9cc
Pool thread stack traces:

Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main]
java.lang.Thread.sleep(Native Method)

com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)

com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main]
java.lang.Thread.sleep(Native Method)

com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)

com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5,main]
java.lang.Thread.sleep(Native Method)

com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)

com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)


8 févr. 2012 15:58:46
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
ATTENTION:
com.mchange.v2.resourcepool.BasicResourcePool$***@7423c7f5 --
Acquisition Attempt Failed!!! Clearing pending acquires. While trying to
acquire a needed new resource, we failed to succeed more than the maximum
number of allowed acquisition attempts (30). Last acquisition attempt
exception:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:264)
at
com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:223)
at
com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
at
com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
at
com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
at
com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
at
com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
at
com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
at
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
at
com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)


--
View this message in context: http://tomcat.10.n6.nabble.com/java-sql-SQLException-No-suitable-driver-found-for-in-tomcat-6-0-35-is-the-class-loading-changed-tp2111551p4376238.html
Sent from the Tomcat - User mailing list archive at Nabble.com.
Anshul katta
2012-02-08 15:59:18 UTC
Permalink
its about the driver....u have to provide the correct driver available
for connection
for eg

com.mysql.jdbc.Driver

and the url for connection
Post by Florian Desbois
Hello,
I have the same issue with c3p0 0.9.1.2. Even if i put the mysql-connector
inside the webapp (instead of CATALINA_HOME/lib), the issue appears.
I also tried to put both c3p0 and mysql-connector in CATALINA_HOME/lib but
the same problem occurs. There is no issue when using tomcat 6.0.33.
I notice that using JNDI is a best practice, but it's a little bit of work
to do it now (lots of projects). Do you have any idea, why it doesn't work
anylonger ?
--- stackTrace ---
8 févr. 2012 15:58:37
com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run
-- APPARENT DEADLOCK!!! Creating emergency threads for unassigned pending
tasks!
8 févr. 2012 15:58:37
com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector run
Managed Threads: 3
Active Threads: 3
(com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
(com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)
(com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)
Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0,5,main]
java.lang.Thread.sleep(Native Method)
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)
com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main]
java.lang.Thread.sleep(Native Method)
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)
com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1,5,main]
java.lang.Thread.sleep(Native Method)
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1805)
com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
8 févr. 2012 15:58:46
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask run
Acquisition Attempt Failed!!! Clearing pending acquires. While trying to
acquire a needed new resource, we failed to succeed more than the maximum
number of allowed acquisition attempts (30). Last acquisition attempt
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:264)
at
com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:223)
at
com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
at
com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
at
com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
at
com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
at
com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
at
com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
at
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
at
com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
--
http://tomcat.10.n6.nabble.com/java-sql-SQLException-No-suitable-driver-found-for-in-tomcat-6-0-35-is-the-class-loading-changed-tp2111551p4376238.html
Sent from the Tomcat - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
Florian Desbois
2012-02-08 17:02:12 UTC
Permalink
Thanks, it was that ! I missed the mysql driverClass in the dataSource.

Strange that with tomcat 6.0.33 i haven't the problem.
Post by Anshul katta
its about the driver....u have to provide the correct driver available
for connection
for eg
com.mysql.jdbc.Driver
and the url for connection
--
View this message in context: http://tomcat.10.n6.nabble.com/java-sql-SQLException-No-suitable-driver-found-for-in-tomcat-6-0-35-is-the-class-loading-changed-tp2111551p4376572.html
Sent from the Tomcat - User mailing list archive at Nabble.com.

Loading...