我想连接到 sql server express。我下载了这个驱动。我阅读了帮助文件,这是我的代码:
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://localhost;database=ActorsDb;integratedSecurity=true;";
Connection con = DriverManager.getConnection(connectionUrl);
PreparedStatement st = con.prepareStatement("INSERT INTO Actors(FirstName,LastName,Age) VALUES(?,?,?)");
st.setString(1, "Robert");
st.setString(2, "de Niro");
st.setInt(3,45);
st.executeUpdate();
con.close();
}
catch (SQLException | ClassNotFoundException e)
{
e.printStackTrace();
}
我得到这个例外: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.".
我关闭了防火墙,但没有任何改变。
我去了 SQL Server 配置管理器并启用了 TCP/IP
我去了IP地址,IP1并设置属性
主动:是;启用:是;TCP 动态端口:[空] ; TCP 端口:1433
关于我所缺少的任何提示?谢谢。