如何在 MS SQL Server 2008 Express 中使用 MS JDBC 驱动程序? [英] How can I use the MS JDBC driver with MS SQL Server 2008 Express?

查看:20
本文介绍了如何在 MS SQL Server 2008 Express 中使用 MS JDBC 驱动程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的配置:

  • Windows XP SP3
  • JDBC 2005
  • MS SQL Server 2008 Express,通过 1433 端口上的 tcp/ip 公开
  • 类路径中的sqljdbc.jar

我试过了:

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();
}

但总是抛出异常:

java.sql.SQLException: No suitable driver

我还尝试了以下网址:

localhost:1433/SQLEXPRESS2008

localhost/SQLEXPRESS2008

localhost

同样的结果.有什么帮助吗?

Same results. Any help?

推荐答案

您的网址错误.

我不知道您所说的JDBC 2005"是什么意思.当我查看微软网站时,我发现了一个叫做 Microsoft SQL Server JDBC 驱动程序 2.0.你会想要那个 - 它包括许多修复和一些性能改进.

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

您的类名似乎正确,但 URL 错误.

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

Microsoft 在 JDBC 驱动程序的初始发布后更改了类名和 URL.您使用的 URL 与 Microsoft 的原始 JDBC 驱动程序一致,MS 称为SQL Server 2000 版本".但该驱动程序使用不同的类名.

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.

对于所有后续驱动程序,URL 更改为我在此处提供的形式.

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

这是在 JDBC 驱动程序的发行说明中.

This is in the release notes for the JDBC driver.

这篇关于如何在 MS SQL Server 2008 Express 中使用 MS JDBC 驱动程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆