java.sql.SQLException: No suitable driver found for jdbc: mysql: // localhost / myDB

advertisements

I am facing same problem. I am using following db url fetched from pom.xml file

jdbc:mysql://localhost/myDB?autoReconnect=true&createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf-8

and driver class is : com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource

when I deploy war of my application in tomcat and hit the url, it gives error :

java.sql.SQLException:No suitable driver found for jdbc:mysql://localhost/myDB?autoReconnect=true&createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf-8

but if I start tomcat in eclipse and hit the url, I never get such error. It's working as expected.

How to fix this issue?


When you run your app from Eclipse, you are running it in a special test tomcat container and eclipse is setting everything up for you.

When you run your app in Tomcat outside Eclipse, you must set up all required libraries yourself. This includes ensuring that the JDBC drivers are available. You need to place the JDBC drivers jar file into TOMCAT_HOME/lib folder for them to be picked up correctly.

Have a look at the tomcat documentation, specifically, section MySQL DBCP Example.