测试JDBC连接sqlserver2000时的奇葩错误,数据库在其他电脑上,局域网内。

吥冷 发布于 2014/02/11 17:02
阅读 1K+
收藏 0

代码部分:

public static void main(String[] args) {


Connection conn = null;
Statement ps = null;
ResultSet rs = null;

//因为测试远程1433被占用,所以就修改为1443端口。
final String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
final String URL = "jdbc:sqlserver://192.168.0.104:1443;databasename=gpsdb";
final String USER = "sa";
final String PASS = "sa";


try {
System.out.println("打开连接");
Class.forName(DRIVER); // 加载驱动
conn = DriverManager.getConnection(URL, USER, PASS); // 连接
if (conn != null) {
System.out.println("连接成功!");
}
} catch (Exception e) {
System.out.println("打开连接异常");
e.printStackTrace();
} finally {
try {
if (rs != null) {
rs.close();
System.out.println("rs关闭");
}
if (ps != null) {
ps.close();
System.out.println("ps关闭");
}
if (conn != null) {
conn.close();
System.out.println("conn关闭");
}
} catch (Exception e) {
System.out.println("关闭异常");
e.printStackTrace();
}
}


}


数据库驱动是最新的

微软官网  提供下载的,兼容sqlserver2000  20005 及以上。


打开连接

二月 11, 2014 4:39:19 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:19 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:19 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:19 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:20 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:20 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:21 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:21 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:22 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:22 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:23 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:23 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:24 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:24 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:25 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:25 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:26 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:26 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:27 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:27 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:28 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:28 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:29 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:29 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:30 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:30 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:31 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:31 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:32 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:32 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:33 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
二月 11, 2014 4:39:33 下午 com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
警告: ConnectionID:1 Prelogin error: host 192.168.0.104 port 1443 Unexpected end of prelogin response after 0 bytes read
打开连接异常
com.microsoft.sqlserver.jdbc.SQLServerException: 通过端口 1443 连接到主机 192.168.0.104 的 TCP/IP 连接失败。错误:“驱动程序收到意外的登录前响应。请验证连接属性,并检查 SQL Server 的实例正在主机上运行,且在此端口接受 TCP/IP 连接。该驱动程序只能与 SQL Server 2000 或更高版本一起使用。”。
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1352)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1339)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.Prelogin(SQLServerConnection.java:1135)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1038)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:817)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:700)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:842)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at demo.conn.main(conn.java:24)

加载中
0
爬树猪
爬树猪
数据库没有配置允许远程连接。
吥冷
吥冷
1433端口找不到,应该就是补丁的问题。
吥冷
吥冷
回复 @无尽的编码 : 找到问题的所在了,2000数据库版本是8.00.194 ,没有打sp4补丁。
爬树猪
爬树猪
回复 @大仙aaa : 1,不允许远程连接;2,防火墙导致。给个找个资料看下http://zhidao.baidu.com/question/224066444.html
吥冷
吥冷
你的意思在数据库那儿配置允许远程?
返回顶部
顶部