gpt4 book ai didi

Java2MySQL > 由于基础异常再次导致通信链接失败

转载 作者:行者123 更新时间:2023-11-29 00:36:08 25 4
gpt4 key购买 nike

我正在用 Java 编写程序,它连接到 MySQL 数据库。由于第一类是具有返回 java.sql.Connection 的单个静态方法的类。在调试并且连接正常后,我再也没有碰过它。几天前我发现我的程序返回了这个错误:

com.mysql.jdbc.CommunicationsException:
Communications link failure due to underlying exception

BEGIN NESTED EXCEPTION
com.mysql.jdbc.CommunicationsException

MESSAGE:
Communication link failure due to underlying exception:

BEGIN NESTED EXCEPTION
java.io.EOFException MESSAGE: Can not read response from server. Expected 4 bytes, read 0 before connection was unexpectedly lost.

STACKTRACE:

...

  • 我安装了 MySQL Server v. 5.1.62
  • 我正在使用 MySQL/J connector v. 5.0.8(从 mysql.com 下载)
  • 我还在 NetBeans sqljdbc4.jar 中放入类路径

我无法理解的是,自创建数据库以来,我并没有更改本地主机上的用户名和密码。我唯一改变的是:添加更多表并更改表中的列,但这不会触发此错误。我对项目所做的事情是将字符集从 UTF-8 更改为 UTF-16,但我想这几乎不会影响我的连接方法。

如果我更改连接器并放入类路径连接器 v.5.1.22,它会返回错误:
拒绝用户“root@localhost”访问(使用密码:YES)
甚至我为用户 root 声明了所有权限。

最佳答案

我会推荐以下内容:

  1. Firstly confirm if network is fine between two servers: a. ping from your server to your database server. b. use MTR unix tool to ensure connectivity between two servers.
  2. Are you using connection pool ? If yes, then try to restart the server. Probably few of the connections in your connection pool are in closed state.

先解决第一个问题。其他问题 Access denied for user "root@localhost"(using password: YES) 是一个独立的问题,我们稍后再讨论。

关于Java2MySQL > 由于基础异常再次导致通信链接失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14231238/

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