import java.sql.*;
class Test1{
public static void main(String args[])
{
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=booksys";
String user ="sa";
String password = "mayer";
String sqlStr = "select * from booktest"; try{ //这里的异常处理语句是必需的.否则不能通过编译!
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
System.out.println( "类实例化成功!" ); Connection con = DriverManager.getConnection(url,user,password);
System.out.println( "创建连接对像成功!" ); Statement st = con.createStatement();
System.out.println( "创建Statement成功!" ); ResultSet rs = st.executeQuery(sqlStr);
System.out.println( "操作数据表成功!" );
System.out.println( "----------------!"); while(rs.next())
{
System.out.print(rs.getString("编号") + " ");
System.out.print(rs.getString("书籍名称") + " ");
System.out.println(rs.getString("出版社名称"));
}
rs.close();
st.close();
con.close();
}
catch(Exception err){
err.printStackTrace(System.out);
}
}
}
错误提示为:java.sql.SQLException:[Microsoft][SQLServer 2000 Driver for Jdbc] error establising sokcet!
请问这是什么原因呀!
我已经装了sql for jdbc 1.3呀,而且classpath设置一点都没有问题,这点我保证,
class Test1{
public static void main(String args[])
{
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=booksys";
String user ="sa";
String password = "mayer";
String sqlStr = "select * from booktest"; try{ //这里的异常处理语句是必需的.否则不能通过编译!
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
System.out.println( "类实例化成功!" ); Connection con = DriverManager.getConnection(url,user,password);
System.out.println( "创建连接对像成功!" ); Statement st = con.createStatement();
System.out.println( "创建Statement成功!" ); ResultSet rs = st.executeQuery(sqlStr);
System.out.println( "操作数据表成功!" );
System.out.println( "----------------!"); while(rs.next())
{
System.out.print(rs.getString("编号") + " ");
System.out.print(rs.getString("书籍名称") + " ");
System.out.println(rs.getString("出版社名称"));
}
rs.close();
st.close();
con.close();
}
catch(Exception err){
err.printStackTrace(System.out);
}
}
}
错误提示为:java.sql.SQLException:[Microsoft][SQLServer 2000 Driver for Jdbc] error establising sokcet!
请问这是什么原因呀!
我已经装了sql for jdbc 1.3呀,而且classpath设置一点都没有问题,这点我保证,
2、确定你安装的是企业版,不是个人版(个人版根本没打开1433端口,只能通过odbc连)
光设置classpath是没用的