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

Hibernate :No suitable driver found for jdbc:sqlserver://localhost:1433;DatabaseName=XXX

 
Hitesh Kumar C
Ranch Hand
Posts: 35
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I was trying to connect SQL Server 2005 through JDBC. Here is my Hibernate Configuration File :




I added the latest SQL JDBC 4.0 jar to my Eclipse Project Build classpath, but it is throwing an exception while running application :



I tried the connection string with username and password also but that also didn't worked for me.

The same URL is working fine for me on a Console Java Application, but since i am trying this on this web, so i think it is not able to find the SQLJDBC4.0.jar on the Server path.

Where i can add the Jar apart from Project Classpath so it will search the Appropriate Driver from the Jar?

I added SQLJDBC4.0 jar under Project > Properties > Libraries.

Kindly suggest?

Any comments and help is greatly appreciated.

 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You must have the class:
com.microsoft.sqlserver.jdbc.SQLServerDriver
in your classpath. Database vendors usually provide drivers for Java. When you are using Hibernate in a standalone application you can load the driver's class manually:
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you run your application, is it running standalone or within an application server?
 
Hitesh Kumar C
Ranch Hand
Posts: 35
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
#James Boswell
It is running on Web Application Server(JBoss). In Console it is working perfectly fine!

#Lucas Smith
I added the jar to the Project classpath having the SQLServerDriver class. I think that automatically uploads the file on the Server.
I tried this also:


but, didn't worked.
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that your JAR that contains the driver is not deployed on the server. What kind of an archive do you use? Is it WAR or EAR?
 
Hitesh Kumar C
Ranch Hand
Posts: 35
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WAR
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hitesh

Adding the jar to the classpath within eclipse does not automatically add it to the server's classpath when your application is deployed.

What version of JBoss are you using? Prior to version 7, the standard location for additional jar files is <JBOSS_HOME>/server/<INSTANCE_NAME>/lib

If you using a standard instance, your <INSTANCE_NAME> will be default.
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so change the file extension of this file from war to zip, extract it and take a look if the extracted folder WEB-INF/lib contains JAR with the driver.
However James Boswell has a good idea - the driver should be placed in the application server's lib folder.
 
Hitesh Kumar C
Ranch Hand
Posts: 35
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lucas Smith
Yes, the file is there.

James Boswell
Let me try that and get back.
 
Hitesh Kumar C
Ranch Hand
Posts: 35
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James Boswell
Thanks for your help. It worked for me!
I copied the Sqljdbc4.0.jar to E:\Servers\jboss-6.1.0.Final\server\default\lib and working fine.
I thought that the Server automatically will take care of the classpath uploads.


Lucas Smith
Thanks for your suggestions and efforts.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic