gpt4 book ai didi

java - 当我尝试连接数据库时 jdbc.SQLServerException

转载 作者:行者123 更新时间:2023-12-02 09:51:37 26 4
gpt4 key购买 nike

我有用于从 JavaFx 应用程序连接到数据库的类

public class DBConnection {

public static Connection mcConnection() {
Connection connection = null;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url = "jdbc:sqlserver://localhost; databaseName=McQueen_db;";
connection = DriverManager.getConnection(url);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}

return connection;
}

}

当我尝试连接时出现异常

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host 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.".

我检查了我的防火墙,一切正常。我想那个港口也是。有什么想法有什么问题吗?

最佳答案

尝试将“localhost”更改为“127.0.0.1”

有时,您的系统无法正确映射本地主机。

引用official doc

关于java - 当我尝试连接数据库时 jdbc.SQLServerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56282256/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com