gpt4 book ai didi

mysql - .com.mysql.jdbc.exception.jbbc4.communicationException..通信链路故障

转载 作者:行者123 更新时间:2023-11-29 23:30:29 26 4
gpt4 key购买 nike

当我尝试使用连接数据库的 java 应用程序时,我收到了上述消息。

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

这里我会提到我的java应用程序中的一些java代码;我用来连接数据库的。

jDBC 驱动程序名称和数据库 URL

static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
static final String DB_URL = "jdbc:mysql://localhost/SORTS";

用户名和密码

static final String USER = "root";
static final String PASS = null;

注册 JDBC 驱动

  Class.forName("com.mysql.jdbc.Driver");

//“正在连接到选定的数据库...”

conn = DriverManager.getConnection(DB_URL, USER, PASS);

我认为这些 MySql 服务器信息也可能有用

current database:sorts
current user:root@localhost
Connection:localhost via TCP/IP
TCP port:3307

最佳答案

在 URL 中,您应该添加使用的端口号 3307(这不是标准端口号...):

 static final String DB_URL = "jdbc:mysql://localhost:3307/SORTS";

希望有帮助。

关于mysql - .com.mysql.jdbc.exception.jbbc4.communicationException..通信链路故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26626109/

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