Reputation: 145
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?
Upvotes: 0
Views: 6657
Reputation: 1827
Add the following dependency to your pom:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.26</version>
</dependency>
and the jar to TOMCAT_HOME/lib
folder.
Upvotes: 2
Reputation: 57346
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.
Upvotes: 2