一个简单的数据库程序,如下所示,上次用的时候还是好的,今天运行了就出了错,找不出原因,请各位帮忙:import java.sql.Connection;
import java.sql.SQLException;
import java.sql.DriverManager;
import java.sql.*;public class dbTest{
public static void main(String args[]) throws Exception{
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://MYWIN2000:1433;DatabaseName=finance_db";
String user="sa";
String password="1234";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement();
String sql="select * from employee_info";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
System.out.print(rs.getString(1)+",");
System.out.print(rs.getString(2)+",");
System.out.println(rs.getString(3));
}
System.out.println("database connect successfully.");
rs.close();
stmt.close();
}
catch (ClassNotFoundException e1){
System.err.println("ClassNotFoundException."+e1);
}
catch (SQLException e2){
System.err.println("SQLException."+e2);
}
}
}编译没错,运行的时候出现了以下错误:SQLException.java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]E
rror establishing socket.请各位帮忙解决一下问题,谢谢!
import java.sql.SQLException;
import java.sql.DriverManager;
import java.sql.*;public class dbTest{
public static void main(String args[]) throws Exception{
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://MYWIN2000:1433;DatabaseName=finance_db";
String user="sa";
String password="1234";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement();
String sql="select * from employee_info";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
System.out.print(rs.getString(1)+",");
System.out.print(rs.getString(2)+",");
System.out.println(rs.getString(3));
}
System.out.println("database connect successfully.");
rs.close();
stmt.close();
}
catch (ClassNotFoundException e1){
System.err.println("ClassNotFoundException."+e1);
}
catch (SQLException e2){
System.err.println("SQLException."+e2);
}
}
}编译没错,运行的时候出现了以下错误:SQLException.java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]E
rror establishing socket.请各位帮忙解决一下问题,谢谢!
http://www.microsoft.com/sql/downloads/2000/sp3.asp
可到sql enterprice manager->指定server->内容->安全性.
把验证改为 SQL server 及 windows.#点选属性检查一下port是否正确.