http://hi.baidu.com/fpbest/blog/item/c9c7ce13df11e0e0c3ce790b.html
第一步:下載安裝Microsoft SQL Server 2000 Service Pack 4,也就是sql2000的sp4補丁
地址如下:
http://www.microsoft.com/downloads/zh-cn/details.aspx?familyid=8e2dfc8d-c20e-4446-99a9-b7f0213f8bc5&displaylang=zh-cn
第二步:下載jdbc的驅動,解壓到任一位置中,:
http://www.microsoft.com/downloads/zh-cn/details.aspx?FamilyID=a737000d-68d0-4531-b65d-da0f2a735707
第三步:就是建立一個java工程,再在windows->preferences->java ->installed jres
再用下面的代碼測試下:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class ConnectAccess {
public static void main(String[] args) {
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=pubs","sa","123456");
Statement stmt =con.createStatement();
ResultSet rs =stmt.executeQuery("select fname,minit,lname from employee");
while (rs.next()){
System.out.print("\t fname:"+rs.getString(1));
System.out.print("\t minit:"+rs.getString(2));
System.out.print("\t lname:"+rs.getString(3));
System.out.println();
}
rs.close();
stmt.close();
con.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
成功了,哈哈!!!
運行代碼前一定要先運行sql伺服器,別忘了哦!!!