我知道這是一個重複的問題。我發現了非常類似的問題和解決方案,但我仍然對它感到震驚。連接到SQL服務器時的SQL異常
我使用eclipse連接我的java應用程序與微軟sql server 2008數據庫。下面是我的代碼
import java.sql.*;
public class ConnectionTest2 {
public static void main(String [] args) {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://localhost:1433;databaseName=Sample;integratedSecurity=true";
Connection con = DriverManager.getConnection(connectionUrl,"","");
System.out.println("Connected");
} catch (SQLException e) {
System.out.println("SQL Exception: "+ e.toString());
}
catch (ClassNotFoundException cE) {
System.out.println("Class Not Found Exception: "+ cE.toString());
}
}
}
我已經去到SQL Server Configuration Manager和IPALL下的端口號設置爲1433啓用TCP/IP和VIA。
我試過很多方法,但我無法找到一個解決方案,以下面的錯誤
SQL Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
我還禁用了Windows防火牆,但是無法連接。
請幫助我。
你有沒有防病毒軟件或VPN軟件可能也有防火牆? – 2012-04-05 20:12:22
這可能太基本了,但您確定該端口是否正確且可用? 在cmd中嘗試命令* telnet localhost 1433 *以確保 – 2012-04-05 20:14:15
可能重複[如何使用JDBC連接到Java中的SQL Server 2008數據庫?](http://stackoverflow.com/questions/2451892/how -do -i-connect-to-a-sql-server-2008-database-in-java -with-jdbc) – 2012-04-05 20:15:08