Reputation: 780
I have a web application using a jar file(lib) to access a Database. The jar file when used as a standalone application executes correctly but the webapp received the error:
[01-08-12 13:17:05] - 35266 WARN org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 0, SQLState: 08001
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/myapp
I have read the answers to similar questions but none of them solve my problem.
I am using Maven, where I have added the dependency for the mysql version I am using, 5.1.21. In fact, I have added it for both the Lib and the Webapp.
Before that, I tried to define in Eclipse a Connectivity Driver Definition bound to the same file, that I had copied to WEB-INF/lib in the eclipse project for my Webapp and with the same parameters that I include below for the persistence.xml file
I am not using any java to configure since I do all the configuration in the persistence.xml file(that I have copied to both META-INF folders, the one for the app(lib) and the one for the webapp. I am using Hibernate (4.1.2) through JPA.
The persistence.xml file is like that:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="myappPersistenceUnit"
transaction-type="RESOURCE_LOCAL">
<provider> org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/myapp" />
<property name="javax.persistence.jdbc.user" value="root" />
<property name="javax.persistence.jdbc.password" value="" />
</properties>
</persistence-unit>
</persistence>
the exception that I get is at Runtime, when launching an Http Request to the app, not at the initialization of the webapp, where I haven't seen any errors but this warning appears:
[01-08-12 13:16:39] - 8782 WARN org.hibernate.engine.jdbc.internal.JdbcServicesImpl - HHH000342: Could not obtain connection to query metadata : No suitable driver found for jdbc:mysql://localhost:3306/myapp
I guess this is due to the information being looked up from the database is not necessary at init, and no exception is thrown but the same root cause in both cases.
EDIT:I am using Tomcat 6.0
Any help will be highly appreciated.
Upvotes: 1
Views: 13516
Reputation: 406
I had the same problem with Tomcat 9. Solved by not having the driver jar in both common/lib and WEB-INF/lib (used the former).
Upvotes: 0
Reputation: 981
It seems that you are missing MySql driver in your project. To solve this you need to add mysql-connector.jar. externally to your project. Or if you are using a maven project then use the following dependency in your pom.xml file.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.4</version>
</dependency>
You can use a suitable version if needed!!
Upvotes: 3
Reputation: 31
I also had the same problem some time before, but I solved that issue. There may be different reasons for this exception.
One of them may be that the jar
you are adding to your lib
folder may be old. Try to find out the latest mysql-connector-jar version and add that to your classpath
. It may solve your issue.
Upvotes: 0
Reputation: 996
you should put mysql connector jar with your own code & add jar file with your project.
Upvotes: 1
Reputation: 89169
If you're running your application as a Java Application, Add the JAR file in the Java Build Path, in Eclipse.
Alternatively, I wouldn't put the MSQL jar inside WEB-INF/lib
folder of your web project, instead, I would put it in your Application folder library folder, where the Application Server will load your driver and you can access it from the Application Server container.
Upvotes: 1