SQL 2005 和 eclipse 的问题
publicclassmySQL{privatefinalStringDRIVER="com.microsoft.sqlserver.jdbc.SQLServerDriv...
public class mySQL {
private final String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
private final String URL = "jdbc:sqlserver://localhost:1433;DatabaseName=Grade1";
private String sql = "select name,age from student";
public Connection con;
public Statement stmt;
public ResultSet rs;
public mySQL() {
try {
Class.forName(DRIVER); // 加载驱动器
con = DriverManager.getConnection(URL, "sa", "123456"); // 连接数据库
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
System.out.println("用户名为" + rs.getString(1) + "密码为"
+ rs.getString(2));
}
rs.close();
stmt.close();
con.close();
} catch (ClassNotFoundException ex) { // 因类不存在,加载失败
ex.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
ex.printStackTrace();
}
}
public static void main(String[] args) {
// TODO 自动生成方法存根
new mySQL();
}
}
报错 是
com.microsoft.sqlserver.jdbc.SQLServerException: Unrecognized Windows Sockets error: 997: recv failed
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSChannel.read(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.Prelogin(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at JDBC.mySQL.<init>(mySQL.java:18)
at JDBC.mySQL.main(mySQL.java:38)
com.microsoft.sqlserver.jdbc.SQLServerException: Unrecognized Windows Sockets error: 997: recv failed
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSChannel.read(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.Prelogin(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at JDBC.mySQL.<init>(mySQL.java:18)
at JDBC.mySQL.main(mySQL.java:38) 展开
private final String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
private final String URL = "jdbc:sqlserver://localhost:1433;DatabaseName=Grade1";
private String sql = "select name,age from student";
public Connection con;
public Statement stmt;
public ResultSet rs;
public mySQL() {
try {
Class.forName(DRIVER); // 加载驱动器
con = DriverManager.getConnection(URL, "sa", "123456"); // 连接数据库
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
System.out.println("用户名为" + rs.getString(1) + "密码为"
+ rs.getString(2));
}
rs.close();
stmt.close();
con.close();
} catch (ClassNotFoundException ex) { // 因类不存在,加载失败
ex.printStackTrace();
} catch (SQLException ex) {
ex.printStackTrace();
ex.printStackTrace();
}
}
public static void main(String[] args) {
// TODO 自动生成方法存根
new mySQL();
}
}
报错 是
com.microsoft.sqlserver.jdbc.SQLServerException: Unrecognized Windows Sockets error: 997: recv failed
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSChannel.read(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.Prelogin(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at JDBC.mySQL.<init>(mySQL.java:18)
at JDBC.mySQL.main(mySQL.java:38)
com.microsoft.sqlserver.jdbc.SQLServerException: Unrecognized Windows Sockets error: 997: recv failed
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(Unknown Source)
at com.microsoft.sqlserver.jdbc.TDSChannel.read(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.Prelogin(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.loginWithoutFailover(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at JDBC.mySQL.<init>(mySQL.java:18)
at JDBC.mySQL.main(mySQL.java:38) 展开
1个回答
展开全部
public class mySQL {
private final String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
private final String URL = "jdbc:sqlserver://localhost:1433;DatabaseName=Grade1";
private String sql = "select name,age from student";
public Connection con;
public Statement stmt;
public ResultSet rs;
try {
Class.forName(DRIVER); // 加载驱动器
con = DriverManager.getConnection(URL, "sa", "123456"); // 连接数据库
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
System.out.println("用户名为" + rs.getString(1) + "密码为"
+ rs.getString(2));
}
rs.close();
stmt.close();
con.close();
} catch (ClassNotFoundException ex) { // 因类不存在,加载失败
ex.printStackTrace();
}
}
把它改为这样 直接运行试试!
private final String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
private final String URL = "jdbc:sqlserver://localhost:1433;DatabaseName=Grade1";
private String sql = "select name,age from student";
public Connection con;
public Statement stmt;
public ResultSet rs;
try {
Class.forName(DRIVER); // 加载驱动器
con = DriverManager.getConnection(URL, "sa", "123456"); // 连接数据库
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
System.out.println("用户名为" + rs.getString(1) + "密码为"
+ rs.getString(2));
}
rs.close();
stmt.close();
con.close();
} catch (ClassNotFoundException ex) { // 因类不存在,加载失败
ex.printStackTrace();
}
}
把它改为这样 直接运行试试!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询