0

i am working on jax-rs(jersey) and want to connect to database by using hibernate. my projects works perfectly fine when i debug it as java application but as i run my project on server it gives No suitable driver found for jdbc:mysql://localhost:3306/sample

here is my hibernate.cfg.xml file

the sql exception is here

  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)
Rai Vu
  • 1,595
  • 1
  • 20
  • 30
  • have you included [mysql jdbc driver](https://mvnrepository.com/artifact/mysql/mysql-connector-java/6.0.5) in your classpath? – Yohanes Gultom Mar 08 '17 at 08:38

1 Answers1

2

You have to download the MySQL Connector/J and add it to your class path

If you are using maven you can use this dependency :

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.18</version>
</dependency>
Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140