我試試就知道了,如果我可以使用這些代碼連接的Java到SQL Server:TCP/IP(Java應用程序到SQL Server)
package pkgtry;
import java.sql.*;
public class NewMain {
public static void main(String[] args) {
String connectionUrl="jdbc:sqlserver://(local):1433;DatabaseName=OJT;user=sa;password=''";
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl);
String SQL = "";
stmt = con.createStatement();
rs = stmt.executeQuery(SQL);
while (rs.next()) {
}
}
catch (Exception e) {
e.printStackTrace();
}
finally {
if (rs != null) try { rs.close(); } catch(Exception e) {}
if (stmt != null) try { stmt.close(); } catch(Exception e) {}
if (con != null) try { con.close(); } catch(Exception e) {}
}
}
}
但在我結束它顯示一個錯誤,並說:
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host (local), port 1433 has failed. Error: "null. 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.".
這是什麼意思?如何解決它?
檢查這一點 - http://stackoverflow.com/questions/11820799/com-microsoft-sqlserver-jdbc-sqlserverexception-the-tcp-ip-connection-to-the-ho – Ankit
由於某種原因,我可以打開我的SQL Server配置管理器,它彈出一個錯誤,並說:'無法連接到WMI提供程序。您沒有權限或服務器無法訪問。請注意,您可以使用SQL Server配置管理器管理SQL Server 2005和更高版本的服務器。無效的類[0x80041010]'如何解決它? –
嘗試「以管理員身份運行」 – Ankit