天天看點

jtds"Network error IOException Connection refused: connect"問題解決

用jtds作驅動程式連接配接SQL Server常常遇到這個問題: java.sql.SQLException: Network error IOException Connection refused: connect 下午查了一些資料,算是得到一些資訊,總結一下。 jtds官方網站解釋如下:

Why do I get

java.sql.SQLException: "Network error IOException: Connection refused: connect"

when trying to get a connection?

The

"Connection refused"

exception is thrown by jTDS when it is unable to connect to the server. There may be a number of reasons why this could happen:

  1. The server name is misspelled or the port number is incorrect.
  2. SQL Server is not configured to use TCP/IP. Either enable TCP/IP from SQL Server's Network Utility app or have jTDS connect via named pipes (see the URL format for information on how to do this).
  3. There is a firewall blocking port 1433 on the server.

To check whether TCP/IP is enabled and the port is not blocked you can use "telnet <server_host> 1433". Until telnet doesn't connect, jTDS won't either. If you can't figure out why, ask your network administrator for help.

解決問題當然是先按照官網來檢查了,于是一步步查下來,發現符合現象2,但是通過網絡管理工具察看TCP/IP,正常。而現象确實與上文描述相同,打了sp3,sp4更新檔。後telnet localhost:1433結果老出現在端口23失敗,把防火牆關了,還是錯。啟動telnet服務,用netstat -a看沒有1433,隻好改了ms server得端口,可還錯原來指令錯 telnet localhost 1455不用中間的冒号。可是還是出現“不能打開到“”的連接配接,登入失敗,原來連接配接字元串錯:jdbc:jtds:sqlserver://localhost:1455/<SSH>應該為jdbc:jtds:sqlserver://localhost:1455/SSH

繼續閱讀