*
The moose likes Object Relational Mapping and the fly likes Cannot open connection issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Cannot open connection issue" Watch "Cannot open connection issue" New topic
Author

Cannot open connection issue

David Avrami
Ranch Hand

Joined: Sep 10, 2011
Posts: 30

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 :
ntumba lobo
Ranch Hand

Joined: Oct 21, 2008
Posts: 180
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 ?


SCJP 5 , SCWCD 5, SCEA 5
David Avrami
Ranch Hand

Joined: Sep 10, 2011
Posts: 30

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

Joined: Sep 10, 2011
Posts: 30

any suggestions, ideas will be much appreciated .
ntumba lobo
Ranch Hand

Joined: Oct 21, 2008
Posts: 180
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

Joined: Sep 10, 2011
Posts: 30

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

Joined: Oct 21, 2008
Posts: 180
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

Joined: Sep 10, 2011
Posts: 30

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

Joined: Sep 10, 2011
Posts: 30



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

Joined: Oct 21, 2008
Posts: 180
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

Joined: Sep 10, 2011
Posts: 30

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

Joined: Oct 21, 2008
Posts: 180
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
 
GeeCON Prague 2014
 
subject: Cannot open connection issue