2、装上SQL Server 2000 Driver for JDBC Service Pack 3
下载地址:http://www.microsoft.com/downloads/details.aspx?FamilyId=07287B11-0502-461A-B138-2AA54BFDC03A&displaylang=en
3、安装完SQL Server 2000 Driver for JDBC Service Pack 3,它默认安装在C:Program FilesMicrosoft SQL Server 2000 Driver for JDBC 里,在C:Program FilesMicrosoft SQL Server 2000 Driver for JDBClib 这个目录里有三个jar文件:
msbase.jar,mssqlserver.jar,msutil.jar,一定要记得把这三个文件copy到你所安装的jdk下的jre目里,这里我以的我的安装配置进行解说:
我的jdk是jdk1.5.0_09,默认安装在:
C:Program FilesJava 里,在这个C:Program FilesJava目录下有两个文件夹:
jdk1.5.0_09 目录 和 jre1.5.0_09目录,
前面说的的那三个jar文件一定要copy到jdk1.5.0_09目录里下的jre目录下的lib目录下的ext目录下,我这里的完整路径为:
C:Program FilesJavajdk1.5.0_09jrelibext
4、设置classpath,把这个三个jar文件,加进去
5、sql2000要设置为混合登录模式(windows 和 sql)
-----------------------------------------------------------------------------------------------------------
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/sqlserver/)调用示例JAVA代码
----------------------------------------------------------------------------------------------------------
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.ResultSet;
//import java.*;
class CourseAppl {
private Connection conn;
private String url;
private String serverName;
private String portNumber;
private String databaseName;
private String userName;
private String password;
private String sql;
CourseAppl() {
url = "jdbc:microsoft:sqlserver://";
serverName = "localhost";
portNumber = "1433";
databaseName = "test";
userName = "sa";
password = "";
}
private String getConnectionUrl() {
//System.out.println (url + serverName + ":"
// + portNumber + ";databaseName="
//+ databaseName + ";");
return url + serverName + ":"
+ portNumber + ";databaseName="
+ databaseName + ";";
}
private Connection getConnection() {
try {
System.out.println (getConnectionUrl());
Class.forName("com.microsoft.jdbc.sqlserver.SQLSe 猜你喜欢