Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.sql.SQLException: No suitable driver

 
Omar Mohaidat
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am new in hibernate, i want to on connect DB2 database. but i got this exception:

org.hibernate.exception.JDBCConnectionException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:99)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:160)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:81)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1473)
at Controller.service(Controller.java:34)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:675)
at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:334)
at com.evermind.server.http.HttpRequestHandler.doDispatchRequest(HttpRequestHandler.java:942)
at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:843)
at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:658)
at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:626)
at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:417)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:189)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:163)
at oracle.oc4j.network.ServerSocketReadHandler$ClientRunnable.run(ServerSocketReadHandler.java:275)
at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:237)
at oracle.oc4j.network.ServerSocketAcceptHandler.access$800(ServerSocketAcceptHandler.java:29)
at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:877)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:545)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:133)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)

hibernate.cfg.xml:


and my code is:


the problem appear in this statement
Transaction transaction = session.beginTransaction();

any help please
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
COM.ibm.db2.jdbc.app.DB2Driver


Try using "com.ibm.db2.jdbc.app.DB2Driver", instead.
Is you driver jar file available in classpath?
Also are you using Windows or Unix system to run the app?
 
Omar Mohaidat
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using db2java.jar, but the exception : Caused by: java.sql.SQLException: No suitable driver

I am using Windows Vista to run the application
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're sure that the jar file is in classpath, please check the complete path by opening the jar and see if the Driver file exists in the said location.
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What kind of application is this, web/standalone? If standalone then how you invoke the class (i.e.: command)? If web/enterprise application, where have you put the driver jar?
 
Omar Mohaidat
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the strange is the jar file in classpath and the class is exist but it doesn't work.

i am trying to download latest db2java jar file, do you know where can i download db2java jar file?
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you check if there are two jar files ( different versions), sitting in different location and if that is causing this confusion?
 
Omar Mohaidat
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What kind of application is this, web/standalone? If standalone then how you invoke the class (i.e.: command)? If web/enterprise application, where have you put the driver jar?

this is web appication, i used JDeveloper IDE, in Tools ---> Manage Library i Created my own library , after that i added the library to my project by Libraries and Classpath in project's properties.


Did you check if there are two jar files ( different versions), sitting in different location and if that is causing this confusion?

i think there is no other jar file in different location, because when i remove the jar from classpath and run the application i got this exception
Missing class: COM.ibm.db2.jdbc.app.DB2Driver

i think the problem in the jar file itself, but i can't find any web site to download another version from this jar.
 
Omar Mohaidat
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What kind of application is this, web/standalone? If standalone then how you invoke the class (i.e.: command)? If web/enterprise application, where have you put the driver jar?

this is web appication, i am using JDeveloper 11g IDE, in Tools ---> Manage Library i Created my own library , after that i added the library to my project by Libraries and Classpath in project's properties.


Did you check if there are two jar files ( different versions), sitting in different location and if that is causing this confusion?

i think there is no other jar file in different location, because when i remove the jar from classpath and run the application i got this exception
Missing class: COM.ibm.db2.jdbc.app.DB2Driver

i think the problem in the jar file itself, but i can't find any web site to download another version from this jar.
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is the COM capitalized?
 
Omar Mohaidat
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The db2java jar file contains COM capitalized. so i write the path of COM.ibm.db2.jdbc.app.DB2Driver class as in jar file.
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Omar Mohaidat wrote:....this is web appication, i am using JDeveloper 11g IDE, in Tools ---> Manage Library i Created my own library , after that i added the library to my project by Libraries and Classpath in project's properties.

Just to make sure, do you have the jar file in the lib directory inside the container once the application deployed? And have checked with the DB documentation for the compatible driver with what you have got?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic