在使用JDBC连接mysql时可能会遇到以下错误:

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

解决方法:

String url = "jdbc:mysql://192.168.xxx.xxx:3306/db";
此处的IP部分添加到hosts文件中,并使用hosts中设置的名称进行连接。
例:
String url = "jdbc:mysql://127.0.0.1:3306/db";
变为
String url = "jdbc:mysql://localhost:3306/db";
 
 
练习一下英语:
This error may encountered when using JDBC to connect Mysql:

  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

sulotions:

You need add target IP to your hosts file and name it.

make String url = "jdbc:mysql://192.168.xxx.xxx:3306/db";  be String url = "jdbc:mysql://hostname:3306/db";

example:

String url = "jdbc:mysql://127.0.0.1:3306/db";
change to
String url = "jdbc:mysql://localhost:3306/db";

MySql的Communications link failure解决办法的更多相关文章

  1. com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 解决办法

    09:00:30.307 [http-8080-6] ERROR org.hibernate.transaction.JDBCTransaction -JDBC begin failed com.my ...

  2. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 解决

    感谢大佬:https://blog.csdn.net/a704397849/article/details/93797529 springboot + mybatis多数据库 + druid连接池配置 ...

  3. Java连接MySQL报错:CommunicationsException: Communications link failure

    现象: 报错:Exception in thread "main" com.mysql.cj.jdbc.exceptions.CommunicationsException: Co ...

  4. mysql 5.1超过默认8小时空闲时间解决办法(错误:com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure)

    报错: MySQL第二天早上第一次连接超时报错, com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications lin ...

  5. jdbc 连接mysql Communications link failure的解决办法

    使用Connector/J连接MySQL数据库,程序运行较长时间后就会报以下错误: Communications link failure,The last packet successfully r ...

  6. 异常解决:Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

    异常描述 这个异常通常有如下信息: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failu ...

  7. 解决Java程序连接mysql数据库出现CommunicationsException: Communications link failure错误的问题

    一.背景 最近在家里捣鼓一个公司自己搭建的demo的时候,发现程序一启动就会出现CommunicationsException: Communications link failure错误,经过一番排 ...

  8. 解决MySQL连接超时Communications link failure due to underlying exception

    最近在用一个MySQL的Java连接池的过程中,连接一晚上不释放,第二天就会造成超时的错误,查了一下原因,原来是因为MySQL默认的空闲等待时间是8个小时,一旦空闲超过8个小时,就会抛出异常.异常文本 ...

  9. 解决:com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure(真实有效)

    数据库连接失败 一.例如我在SpringBoot项目中使用了阿里的数据库连接池Driud. 有次在启动的时候,会报这样的错: Caused by: com.mysql.cj.exceptions.CJ ...

随机推荐

  1. 开启远程桌面连接windows的方法以及遇到的问题

    确认电脑的远程服务是否已经开启 开始--运行--输入“services.msc ”,打开服务,找到三个remote desktop开头的服务 Remote Desktop Configuration. ...

  2. BigDecimal 在for循环中相加注意事项

    public static void main(String[] args) { BigDecimal bigDecimal = new BigDecimal(1); for (int i = 0; ...

  3. [已解决]python FileNotFoundError: [WinError 3] for getsize(filepath)

    问题代码: def sourceStatic(path, exclude): # exclude list convert to lower exclude = list(map(lambda x:x ...

  4. [LeetCode] 19. 删除链表的倒数第N个节点

    题目链接:https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/ 题目描述: 给定一个链表,删除链表的倒数第 n 个节点, ...

  5. 数据的偏度和峰度——df.skew()、df.kurt()

    我们一般会拿偏度和峰度来看数据的分布形态,而且一般会跟正态分布做比较,我们把正态分布的偏度和峰度都看做零.如果我们在实操中,算到偏度峰度不为0,即表明变量存在左偏右偏,或者是高顶平顶这么一说. 一.偏 ...

  6. Windows下切分文件(GnuWin32)

    windows下碰到查看大日志文件还真麻烦,今天找了个工具来做这个:安装GnuWin32,然后用里面的split命令分割日志文件 ps:发现intellij idea还挺好,超过2g的日志文件也能进行 ...

  7. springboot开启事务支持时报代理错误

    问题:The bean 'xxx' could not be injected as a 'com.github.service.xx' because it is a JDK dynamic pro ...

  8. centos7之zabbix监控mysql(mariadb)数据库

    一.Zabbix3.2.6使用自带模板监控MySQL 添加zabbix_agent客户端方法:http://www.cnblogs.com/lei0213/p/8858269.html mysql服务 ...

  9. HTML事件属性

    1.常用窗口事件属性 属性 值 描述 onbeforeonload script 在文档加载之前运行脚本 onblur script 当窗口失去焦点时运行脚本 onerror script 当错误发生 ...

  10. Java实训作业

    1.编写程序:声明一个整型变量a,并赋初值5,在程序中判断a是奇数还是偶数,然后输出判断的结果. public class hello{ public static void main(String[ ...