• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting error : No suitable driver found for jdbc:mysql://localhost:3306/sreedb in hibernate

 
sreedevi langoju
Greenhorn
Posts: 4
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am learning Hibernate . I am trying to connect mysql5 using hibernate4 in Eclipse . I added all the necessary jar files in class path . I added mysql-connector jar also in classpath.
But when i am trying run , i am getting this error :

ERROR: No suitable driver found for jdbc:mysql://localhost:3306/sreedb

Exception in thread "main" org.hibernate.exception.JDBCConnectionException: Could not open connection
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:131)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:304)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:169)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:67)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:160)
at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1363)
at test.Client.main(Client.java:27)



hibernate.cfg.xml:
-------------------------------------

<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/sreedb</property>
<property name="connection.username">root</property>
<property name="connection.password">root123</property>
<property name="connection.pool_size">10</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping resource="resources/student.hbm.xml" />

</session-factory>
</hibernate-configuration>


--------------------------------------------

I was able to connect to this database using JDBC with same db url , username and password.
Please help .....

Thanks in advance...
sree
 
Dave Tolls
Ranch Hand
Posts: 2112
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What classpath did you add the jar files into?
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sreedevi langoju,

First of all, a warm welcome to CodeRanch!

sreedevi langoju wrote:I added all the necessary jar files in class path . I added mysql-connector jar also in classpath.
But when i am trying run , i am getting this error :

ERROR: No suitable driver found for jdbc:mysql://localhost:3306/sreedb

This exception can have 2 causes:
  • The JDBC driver is not loaded at all
  • The URL doesn't match any of the loaded JDBC drivers

  • The URL seems to be correct to connect with a MySQL database, so the JDBC driver is not loaded for some reason. Are you sure you have added the required JARs the to (appropriate) class path? Which version of the MySQL JDBC driver are you using? Is it a JDBC 4.0 compliant one?

    Hope it helps!
    Kind regards,
    Roel
     
    Tim Holloway
    Saloon Keeper
    Posts: 18367
    56
    Android Eclipse IDE Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    The mysql-connector jar has been around for a long while now and it would be capable of resolving the driver request.

    I think the 2 deadly words in the question were "in Eclipse".

    Any time the IDE is an important part of the question, it's an indication that the IDE is being expected to do work that the programmer should know how to do.
     
    sreedevi langoju
    Greenhorn
    Posts: 4
    1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks for all your replies ...

    I installed mysql using : mysql-installer-community-5.7.12.0

    Mysql driver jar file : mysql-connector-java-5.0.8-bin

    downloaded : hibernate-release-4.1.2.Final

    I added the jar files to Project -> BuildPath-> Configure BuildPath -> libraries -> add external jars .

    Please check the attached screenshot .

    Please let me know how to fix this error.

    Thanks
    Sree



    screenshot.jpg
    [Thumbnail for screenshot.jpg]
    Error Screenshot
     
    Paul Clapham
    Sheriff
    Posts: 21583
    33
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I tried to scroll down to look at the rest of the stack trace but unfortunately you posted a screenshot so I couldn't do that. This is one of the many disadvantages of posting screenshots instead of text which can be readily copied and pasted. So, over to you. Which line of your code is throwing the exception?

    (If you can't find the answer by looking at the stack trace, then feel free to post it here -- as text -- and people will give you advice.)
     
    Paul Clapham
    Sheriff
    Posts: 21583
    33
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Sorry, I see you did that right at the beginning. However I see that you apparently have two versions of the JDBC jar in your build path. Unless the names of the jars are misleading me, which is always a possibility. Having something in the classpath twice is not a good idea as it can sometimes lead to strange things happening.
     
    Tim Holloway
    Saloon Keeper
    Posts: 18367
    56
    Android Eclipse IDE Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    It wouldn't mean anything anyway.

    The classpath used when you run an app under the Eclipse IDE is set as part of the Run Profile, which is not part of the project. Run/Debug Profiles are stored in the workspace metadata and they can have COMPLETELY different classpaths from what the IDE's compiler is using.
     
    Paul Clapham
    Sheriff
    Posts: 21583
    33
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I never knew that and I've been using Eclipse for years now. Anyway I see that the default in the Run profile is for the classpath to be the build path of the project in which the class to be run is located. Chances are that the OP is using the default.
     
    Tim Holloway
    Saloon Keeper
    Posts: 18367
    56
    Android Eclipse IDE Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I'm not sure that includes the library jars, however.

    Still, I'm fairly certain that this is an IDE problem, not strictly speaking a Hibernate problem.
     
    Paul Clapham
    Sheriff
    Posts: 21583
    33
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    It's a classpath problem, so of course it's not a Hibernate problem.
     
    Roel De Nijs
    Sheriff
    Posts: 10662
    144
    AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Tim Holloway wrote:I'm not sure that includes the library jars, however.

    When I include some library JARs to my project in Eclipse and execute one of the classes with a main method, the included library JARs are always part of the class path by default. So I am not required to add some additional configuration.
     
    Roel De Nijs
    Sheriff
    Posts: 10662
    144
    AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    sreedevi langoju wrote:Please check the attached screenshot .

    Please let me know how to fix this error.

    I see on your screenshot that you seem to have two mysql-connector JARs and that's weird. Can you remove the second one (mysql-connector.jar) from the referenced libraries, because you only need the first one?
     
    Paul Clapham
    Sheriff
    Posts: 21583
    33
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Roel De Nijs wrote:I see on your screenshot that you seem to have two mysql-connector JARs and that's weird.


    That's what I said yesterday, only it was derailed by Tim's excursion into obscure Eclipse features.
     
    sreedevi langoju
    Greenhorn
    Posts: 4
    1
    • Likes 2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you so much for all your replies...


    I tried to execute by removing the extra mysql-connector jar and adding all the jar files to run configurations of my client class, but still i was not able to connect to my db.

    So ,i deleted all the old jar files and downloaded latest hibernate5 version jars and added all jar files which are in lib/ required , lib/java8, lib/jpa , lib/envers folders to my classpath of the project as a library.

    Finally ... now i am able to connect to my database and do the CRUD operations ..

    Thank you all for your support and suggestions ...

    Thanks,
    Sree

     
    Roel De Nijs
    Sheriff
    Posts: 10662
    144
    AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    sreedevi langoju wrote:I tried to execute by removing the extra mysql-connector jar and adding all the jar files to run configurations of my client class, but still i was not able to connect to my db.

    So ,i deleted all the old jar files and downloaded latest hibernate5 version jars and added all jar files which are in lib/ required , lib/java8, lib/jpa , lib/envers folders to my classpath of the project as a library.

    Finally ... now i am able to connect to my database and do the CRUD operations ..

    Glad to hear you were able to fix your problem! So it clearly was some classpath issue. It's a pity you don't know exactly what was causing your problem, but the most important is that you were able to solve and execute the CRUD operations.

    Thanks for coming back and sharing your solution! That might be very helpful for other ranchers as well. Have a cow!

    Kind regards,
    Roel
     
    sreedevi langoju
    Greenhorn
    Posts: 4
    1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Roel
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic