Java2MySQL>由于基础异常再次发生通信链路故障 [英] Java2MySQL > Communication link failure due to underlying exception again

查看:1104
本文介绍了Java2MySQL>由于基础异常再次发生通信链路故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java中创建程序,它连接到MySQL数据库。因为第一个类是单个静态方法返回 java.sql.Connection 的类。在它被调试和连接工作后,我从来不再触摸它。几天前,我发现我的程序返回了此错误:


com.mysql.jdbc.CommunicationsException:
链接失败
由于基础异常

BEGIN NESTED EXCEPTION

com.mysql.jdbc.CommunicationsException

MESSAGE:
通讯链接
由于基础异常导致的失败:

BEGIN NESTED EXCEPTION

java.io.EOFException MESSAGE:无法从服务器读取响应。
预期4个字节,在连接意外丢失之前读取0.



STACKTRACE:
$ b

...





  • 安装MySQL Server v。5.1.62

  • 我使用MySQL / J连接器v。5.0.8(从mysql.com下载)

  • 我也在NetBeans中放入classpath sqljdbc4.jar



我不明白是事实我没有更改用户名和密码在我的localhost从我创建我的数据库。只有我改变的是:在表中添加更多的表和更改的列,但不会触发此错误。我用我的项目做的事情是我将字符集从UTF-8更改为UTF-16,但我想它几乎不能影响我的连接方法。



如果我更改连接器并放在classpath连接器5.1.22中,它返回错误:

用户root @ localhost的访问被拒绝(使用密码:YES)

即使我已为用户root声明了所有权限。

解决方案

我会推荐如下:



  1. 首先确认两台服务器之间的网络是否正常:a。 ping从您的服务器到您的数据库服务器。 b。请使用MTR unix工具
    确保两个服务器之间的连接。

  2. 您是否正在使用连接池?如果是,请尝试重新启动服务器。您的连接池中的连接很可能很少处于
    关闭状态。


首先解决第一个问题。其他问题访问被拒绝的用户root @ localhost(使用密码:是)是一个独立的问题,我们稍后可以讨论。


I'm making program in Java, which connects to MySQL database. As first class was class with single static method returning java.sql.Connection. After it was debugged and connection was working I never touch it again. And few days ago I discovered my program was returning this error:

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:

...

  • I installed MySQL Server v. 5.1.62
  • I'm using MySQL/J connector v. 5.0.8 (downloaded from mysql.com)
  • also I put in classpath in NetBeans sqljdbc4.jar

Thing I can't understand is fact I didn't change user name and password on my localhost since I created my database. Only thing I changed are: add more tables and changed columns in tables, but that would not trigger this error. And thing I did with my project is I changed charset from UTF-8 to UTF-16, but I guess it hardly can affect my connection method.

If I change connector and put in classpath connector v. 5.1.22 it returns error:
Access denied for user "root@localhost" (using password: YES)
even I declared all privileges for user root.

解决方案

I will recommend following:

  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.

Lets firstly resolve the first issue. Other issue Access denied for user "root@localhost" (using password: YES) is an independent issue which we can discuss later.

这篇关于Java2MySQL>由于基础异常再次发生通信链路故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆