简体   繁体   中英

No suitable driver found for jdbc mysql driver

First of all, I know there are a lot of answers about this and I already checked them all, but this is a bit more specific I think.

I am developing a REST web service using Jersey, but I have this little problem when connecting to the mysql database. I have added the connector dependency in the pom.xml:

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.38</version>
</dependency>

And if I check the build options the relative jar is in the eclipse java build path, but I get the error anyway, unless I add

Class.forName("com.mysql.jdbc.Driver");

before creating the connection.
I tried creating a java project adding the connector driver manually in the java build path and it works, so I guess it is something strictly related to maven or tomcat. I am using java 7 and tomcat 7.

这是一个eclipse问题,您必须将jar放在Eclipse Maven Dependencies中,您可以查看: Eclipse中的Maven依赖问题

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM