找不到合适的驱动程序异常:Hibernate

时间:2017-03-08 08:33:14

标签: java mysql hibernate jdbc jersey

我正在使用jax-rs(jersey)并希望使用hibernate连接到数据库。当我将它作为java应用程序调试时,我的项目工作得非常好,但是当我在服务器上运行我的项目时,它没有为jdbc:mysql://localhost:3306/sample找到合适的驱动程序

here is my hibernate.cfg.xml file

sql异常在这里

  Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/sample
      at java.sql.DriverManager.getConnection(Unknown Source)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:208)
      at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:301)
      at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:214)

1 个答案:

答案 0 :(得分:2)

您必须下载MySQL Connector/J并将其添加到您的课程路径

如果您使用的是maven,则可以使用此依赖项:

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.18</version>
</dependency>