积极答复者
SQL Server 2008 R2 Enterprise版JDBC连接假死

问题
-
我在windows server 2008 R2 Enterprise SP1(64位)的系统上安装了SQL Server 2008 R2 Enterprise版,另外有一台Readhat Enterprise 6.3 (64位)的linux服务器,上面有运行的Java程序,通过JDBC4连接SQL server 2008,但是每次连接的时候都会出现假死现象。
测试程序:T.java
import java.sql.*;
public class T {
public static void executeSQLException(Connection con) {
try {
String SQL = "SELECT * from test";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(SQL);
while (rs.next()) {
System.out.println(rs.getString("Message"));
}
stmt.close();
}
catch (SQLException se) {
do {
System.out.println("SQL STATE: " + se.getSQLState());
System.out.println("ERROR CODE: " + se.getErrorCode());
System.out.println("MESSAGE: " + se.getMessage());
System.out.println();
se = se.getNextException();
} while (se != null);
}
}
public static void main(String args[]){
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL = "jdbc:sqlserver://10.10.18.1:8212;databaseName=webflow";
String userName="webflow";
String userPwd="website'sp@ssw0rd";
Connection dbConn;
try{
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL,userName,userPwd);
System.out.println("Connection Successful!");
executeSQLException(dbConn);
}catch (Exception e){
e.printStackTrace();
}
}
}
编译:
[root@web-make01 iflow]# javac T.java
执行:
[root@web-make01 iflow]# java -classpath '.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:./sqljdbc4.jar' T
通过查看两台服务器上的网络连接状态,发现连接已经建立,但是却无任何响应,程序并没有执行查询,也没有任何响应,出现假死状态。
查询SQL Server的系统表发现一个很怪的情况:
SELECT * FROM
[Master].[dbo].[SYSPROCESSES] WHERE [DBID]
IN
(
SELECT
[DBID]
FROM
[Master].[dbo].[SYSDATABASES]
WHERE
NAME='webflow'
)查询结果:
spid kpid blocked waittype waittime lastwaittype waitresource dbid uid cpu physical_io memusage login_time last_batch ecid open_tran status sid hostname program_name hostprocess cmd nt_domain nt_username net_address net_library loginame context_info sql_handle stmt_start stmt_end request_id
119 2348 0 0x0000 0 MISCELLANEOUS 10 1 31 0 2 2013-08-07 14:45:30.920 2013-08-07 14:46:24.180 0 0 runnable 0xA544D0A483A5114C8EF6134DC72B853600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 SBSM-XIAOFEI Microsoft SQL Server Management Studio - 查询 23588 SELECT DATA-WEB Administrator 0023AEA9F8DC Named Pipes webflow 0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0x01000A00DBE34C18705F559F0000000000000000 0 -1 0
120 0 0 0x0000 0 MISCELLANEOUS 10 1 0 0 0 2013-08-07 14:46:42.353 2013-08-07 14:46:42.353 0 0 sleeping 0xA544D0A483A5114C8EF6134DC72B853600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 web-make01 Microsoft JDBC Driver for SQL Server 0 AWAITING COMMAND 000000000000 TCP/IP webflow 0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0x0000000000000000000000000000000000000000 0 0 0假死的这个连接的sql_handle字段的值为:0x0000000000000000000000000000000000000000
而正常的连接的sql_handle字段的值类型:0x01000A00DBE34C18705F559F0000000000000000,并不是全为0。
这种情况大家见过没有,请教一下。
答案
-
看到过很多JDBC的问题,microsoft 呀 jTDS 呀,尽量用最新的把,你的4.0似乎是最新的
假死是因为很多时候jDBC不close properly,建议你的code 能close就close,
If you think my suggestion is useful, please rate it as helpful.
If it has helped you to resolve the problem, please Mark it as Answer.
http://twitter.com/7Kn1ghts- 已标记为答案 Lisa Zhang - MSFTModerator 2013年8月13日 10:00