StoneHeart StoneHeart - 1 month ago 9
Java Question

How can I use the MS JDBC driver with MS SQL Server 2008 Express?

My configuration:


  • windows XP SP3

  • JDBC 2005

  • MS SQL Server 2008 Express, exposed via tcp/ip on port 1433

  • sqljdbc.jar in class path



I tried:

try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433/SQLEXPRESS2008;databaseName=Test;selectMethod=cursor", "sa", "");
}
catch (Exception e) {
e.printStackTrace();
}


But it always throws an exception:

java.sql.SQLException: No suitable driver


I also tried the following urls:

localhost:1433/SQLEXPRESS2008

localhost/SQLEXPRESS2008

localhost


Same results.
Any help?

Answer

You have the wrong URL.

I don't know what you mean by "JDBC 2005". When I looked on the microsoft site, I found something called the Microsoft SQL Server JDBC Driver 2.0. You're going to want that one - it includes lots of fixes and some perf improvements. [edit: you're probably going to want the latest driver. As of March 2012, the latest JDBC driver from Microsoft is JDBC 4.0]

Check the release notes. For this driver, you want:

URL:  jdbc:sqlserver://server:port;DatabaseName=dbname
Class name: com.microsoft.sqlserver.jdbc.SQLServerDriver

It seems you have the class name correct, but the URL wrong.

Microsoft changed the class name and the URL after its initial release of a JDBC driver. The URL you are using goes with the original JDBC driver from Microsoft, the one MS calls the "SQL Server 2000 version". But that driver uses a different classname.

For all subsequent drivers, the URL changed to the form I have here.

This is in the release notes for the JDBC driver.

Comments