簡體   English   中英

jdbc與SQL Server的連接

[英]jdbc connection to SQL Server

這真的很簡單,但是我在連接到SQL Server時遇到問題。 這是用於連接到SQL Server的代碼行:已經嘗試檢查我在網絡上的其他代碼和資源,但無法正常工作。 誰能看看這個。 謝謝

JDBC代碼

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection("jdbc:sqlserver://IP_ADD;databaseName=DB_NAME", "MY_USER", "MY_PASS");

錯誤記錄

Error during process run: The TCP/IP connection to the host IP_ADDRESS, port
1433 has failed. Error: "connect timed out. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.".
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host IP_ADDRESS, port 1433 has failed. Error: "connect timed out. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking
TCP connections to the port.".
        at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(S
QLServerException.java:170)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLSer
verConnection.java:1049)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConne
ction.java:833)
        at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerCon
nection.java:716)
        at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.
java:841)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at LoadTextFile.main(LoadTextFile.java:40)

很明顯的錯誤:

The TCP/IP connection to the host IP_ADDRESS, port 1433 has failed. 

看來您正在為服務器使用IP_ADDRESS常量。 確保IP_ADDRESS具有正確的主機名,(或)將其替換為數據庫URL中的實際服務器名/ IP地址。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM