#re: JDBC连接SQLServer时出现错误Error establishing socket.的解决。回复更多评论
-12-07 00:19 by Angela
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Type4 {
public static void main(String[] args) {
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver")
.newInstance();
System.out.println("数据库驱动程序注册成功!");
String url = "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=Northwind";
String user = "sa";
String password = "sa";
Connection conn = DriverManager.getConnection(url, user, password);
System.out.println("数据库连接成功");
} catch (Exception e) {
e.printStackTrace();
System.out.println("数据库连接失败");
}
}
}
数据库驱动程序注册成功!
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSConnection.(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at Type4.main(Type4.java:14)
数据库连接失败
如果觉得《java报错establishing_JDBC连接SQLServer时出现错误Error establishing socket.的解决。》对你有帮助,请点赞、收藏,并留下你的观点哦!