3

I am using a software that requires jbdc driver (for sql server 2005), my java version is 1.5.0_16.

When I want to start the application, it throws me this exception :

java.sql.SQLException: java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
dorien
  • 5,265
  • 10
  • 57
  • 116
Wael
  • 71
  • 5
  • did you added jdbc driver to `classpath`? – ѕтƒ Apr 29 '14 at 11:36
  • Did you import the jar file of the jdbc? – AdrianES Apr 29 '14 at 11:36
  • Yes I added the jar file – Wael Apr 29 '14 at 11:39
  • I think i had similar problem with sql-server-2000 and i solve it with older jdbc jar. I used the sqljdbc_3.0. – AdrianES Apr 29 '14 at 11:46
  • the new exception is java.sql.SQLException: No suitable driver at java.sql.DriverManager.getConnection – Wael Apr 29 '14 at 11:47
  • If u were using sql server 200 first read this thread. http://blogs.msdn.com/b/jdbcteam/archive/2007/06/15/java-lang-classnotfoundexception-com-microsoft-jdbc-sqlserver-sqlserverdriver.aspx – AdrianES Apr 29 '14 at 11:49
  • Your URL should be jdbc:sqlserver://server:port;DatabaseName=dbname and Class name should be like com.microsoft.sqlserver.jdbc.SQLServerDriver Use MicrosoftSQL Server JDBC Driver 2.0 http://www.microsoft.com/downloads/en/details.aspx?FamilyID=99b21b65-e98f-4a61-b811-19912601fdc9&displaylang=en – AdrianES Apr 29 '14 at 11:53

2 Answers2

2

The CLASSPATH variable is the search string that Java Virtual Machine (JVM) uses to locate the JDBC drivers on your computer. If the drivers are not listed in your CLASSPATH variable, you receive the following error message when you try to load the driver:

java.lang.ClassNotFoundException: com/microsoft/jdbc/sqlserver/SQLServerDriver 

The JDBC driver is not part of the Java SDK. If you want to use it, you must set the classpath to include the sqljdbc.jar file or the sqljdbc4.jar file. If the classpath is missing an entry for sqljdbc.jar or sqljdbc4.jar, your application will throw the common "Class not found" exception.

The sqljdbc.jar file and sqljdbc4.jar file are installed in the following location:

<installation directory>\sqljdbc_<version>\<language>\sqljdbc.jar
<installation directory>\sqljdbc_<version>\<language>\sqljdbc4.jar

The following is an example of the CLASSPATH statement that is used for a Windows application:

CLASSPATH =.;C:\Program Files\Microsoft JDBC Driver 4.0 for SQL Server\sqljdbc_4.0\enu\sqljdbc.jar 

The following is an example of the CLASSPATH statement that is used for a Unix/Linux application:

CLASSPATH =.:/home/usr1/mssqlserverjdbc/Driver/sqljdbc_4.0/enu/sqljdbc.jar 

You must make sure that the CLASSPATH statement contains only one Microsoft JDBC Driver for SQL Server, such as either sqljdbc.jar or sqljdbc4.jar.

For more information, please see:

support ms

msdn ms

-2

Is the driver class name correct?

Shouldn't it be

"com.microsoft.sqlserver.jdbc.SQLServerDriver"
Hirak
  • 3,601
  • 1
  • 22
  • 33