这是我的 Java 代码:
import java.sql.*;
public class Database_connect
{
public static void main(String[] args) {
String url= "jdbc:sqlserver://localhost:1433;DatabaseName=Reena;instance=SQLSERVER;encrypt=true;TrustServerCertificate=true";
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.println("Driver added");
Connection con=DriverManager.getConnection(url,"sa","Reena123");
System.out.println("connection established.");
con.close();
}
catch(ClassNotFoundException e)
{
System.out.println("Driver not loaded");
}
catch(SQLException e)
{
System.out.println("Not connected."+e.getMessage());
}
}
}
我已经检查了所有这些错误提到的东西。
但它仍然给我这个错误:
与主机 localhost 端口 1433 的 TCP/IP 连接失败。
错误:“连接超时。”</p>
我能做些什么来解决这个问题?