• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cannot open connection issue

 
Ranch Hand
Posts: 30
Hibernate C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
i am trying to get connected to my data base with Hibernate but it kips telling me : Cannot open connection. i am new at this so i may have done some thing wrong
or missed some step(more likely).




my hibernate.cfg.xml :
 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you look at the bottom of your stacktrace you will see the cause of the error:
"Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql:///haimgavriel"

It looks like you dont have the correct driver in your classpath.
What version of mysql is your database and what is the name of your JDBC driver jar ?
 
David Avrami
Ranch Hand
Posts: 30
Hibernate C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my sql version is : 5.1.46
and my drivers name : mysql-connector-java-5.1.7-bin.jar

i have already used it and got app's working with MySql DB but with:
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

thank you for the fast reply.
 
David Avrami
Ranch Hand
Posts: 30
Hibernate C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
any suggestions, ideas will be much appreciated .
 
ntumba lobo
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
stupid question havent you got one slash too many in your jdbc url ?
shouldnt it be "jdbc:mysql://haimgavriel" instead of "jdbc:mysql:///haimgavriel"?
 
David Avrami
Ranch Hand
Posts: 30
Hibernate C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no. in this way i tell him to search for my scheme (haimgavriel)
what you are saying is i should write the full path like:
jdbc:mysql://localhost:3306/haimgavriel
but it's not working either.

Its not having any deal with the error but i have updated my cfg file: (added 3 classes)



thanks for the reply
 
ntumba lobo
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you make any progress on your issue?
Just in case I found the following from mysql documentation:

20.3.5.3.2: My application throws an SQLException 'No Suitable Driver'. Why is this happening?

There are three possible causes for this error:

1 The Connector/J driver is not in your CLASSPATH, see Section 19.3.2, “Connector/J Installation”.
2The format of your connection URL is incorrect, or you are referencing the wrong JDBC driver.
3When using DriverManager, the jdbc.drivers system property has not been populated with the location of the Connector/J driver.

As you dont use DriverManager it is either 1 or 2.
The url "jdbc:mysql://localhost:3306/haimgavriel" looks fine.
You seem to be using Tomcat so make sure the driver is in the servervclasspath for tomcat 6+ its TOMCAT_HOME/lib.
 
David Avrami
Ranch Hand
Posts: 30
Hibernate C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for replying
Yes, i am still on it, i have been so busy the past 3 days.
any way, i have tried to relocate the driver file and it didn't worked as: external, web app or tomcat lib.
Don't know why but when i putted the driver file as external jar it sad: Null pointer exception, like he didn't see it.
so it is now in my tomcat lib.

the interesting thing is that when i am using the driver manager as:



and in the same session i am using hibernate the first one does work, the hibernate don't. (same problem)
then i thought maybe i broke some limit, so i tried to use only hibernate..still, same problem remains.

maybe something to do with a class i am using to initialize FactorySession:

 
David Avrami
Ranch Hand
Posts: 30
Hibernate C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Solved it..
putted the driver in the jre folder.
i am only guessing that it matters because the driver should have been loaded at an earlier stage.
 
ntumba lobo
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It may be working with the driver in the jre/lib/ext but this is only a solution acceptable in a local dev environment.
You need to figure out why your server cannot see the JDBC driver in its lib folder. It will benefit you in the future.
Nice work around anyway.
 
David Avrami
Ranch Hand
Posts: 30
Hibernate C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
your right!!!
that thought was in my mind for a second and then vanished because i was so glad it worked.
I have to figure it out, will post as soon as i'll have the answer.
 
ntumba lobo
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I needed to create a small hibernate project for some other business of mine.
It uses hibernate 3, mysql 5 and tomcat 6 and works just fine.
I could package it with tomcat and send it over to you for comparison if you wish to.
Send me private msg for that
 
reply
    Bookmark Topic Watch Topic
  • New Topic