4 Replies Latest reply on Jun 13, 2012 2:50 PM by Wolf-Dieter Fink

    JBoss 7.1: No suitable driver found java:mysql - could not open connection

    Maciej S Newbie

      I was looking for an answer but didn't find solution. I'm developing simple web-app using JSF2 and Hibernate. This is first time I'm using Hibernate and I'm facing many problems with configuration. My current issue is: I configured mysql connector as a module in JBoss7.1 modules. Then I created datasource and added mysql-connector-java-5.1.20-bin.jar to the classpath (It is in WEB-INF/lib directory in .war). After starting JBoss I'm getting following logs:

      23:44:07,497 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
      23:44:07,603 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
      ...
      23:44:20,348 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) JBAS010404: Deploying non-JDBC-compliant driver class com.mysql.jdbc.Driver (version 5.1)
      23:44:21,532 INFO 
      ...
      [org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl] (MSC service thread 1-3) HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost/testdb]
      23:44:21,535 INFO  [org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl] (MSC service thread 1-3) HHH000046: Connection properties: {user=root}
      23:44:21,556 WARN  [org.hibernate.engine.jdbc.internal.JdbcServicesImpl] (MSC service thread 1-3) HHH000342: Could not obtain connection to query metadata : No suitable driver found for jdbc:mysql://localhost/testdb

      And then application is deployed and server starts successfully. When I try to invoke method trying to persist some data I obtain

      org.hibernate.exception.JDBCConnectionException: Could not open connection
      and
      java
      .sql.SQLException: No suitable driver found for jdbc:mysql://localhost/testdb

      I'm sure the mysql-connector-java-5.1.20-bin.jar is in the WEB-INF/lib directory in war file. Any ideas what am I missing here? MySQL server wersion is 5.1.63, but I don't think it is relevant here. Thank's a lot in advance!

      I also tried to test this functionality outside the container, but now I'm really confused, because code is working well. I created class which uses the same code (HIbernateUtil to obtain session factory) and there are no exceptions, and data is inserted to DB. Could anyone please explain me why it is working in that way, and why it is not working under the container? And how to fix this, because I have no idea... Thank you very much!