java文件不能连接数据库,我的系统是XP_SP2,已经安装了SP2的补丁的chs_sql2ksp3.exe 了,但是还是抛出错误:"Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.".
请指导一下!
package jDBC;
package jDBC;
import java.sql.*;
public class Test {
public Test(){
}
public void conn(){
try{
String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
System.out.println("??");
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Test";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url,"sa","");
Statement stmt = conn.createStatement();
String sql ="select * from jobs";
ResultSet rs= stmt.executeQuery(sql);
while(rs.next()){
String id= rs.getString("job_id");
System.out.println(id);
}
}
catch(Exception e){
System.out.print(e.getMessage());
}
}
public static void main(String args[])throws Exception{
new Test().conn();
}
}
------解决方法--------------------------------------------------------
强烈建议改用 jtds 驱动程序试试 http://jtds.sourceforge.net/
------解决方法--------------------------------------------------------
1433端口没打开。sqlserver2000打上sp4吧