在使用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. SQLServer创建用户登录

    创建用户登录注意事项 密码是区分大小写的. 只有创建SQL Server登录时,才支持对密码预先进行哈希运算. 如果指定MUST_CHANGE,则CHECK_EXPIRATION和 CHECK_POL ...

  2. web安全—sql注入漏洞

    SQL注入-mysql注入 一.普通的mysql注入 MySQL注入不像注入access数据库那样,不需要猜.从mysql5.0以上的版本,出现一个虚拟的数据库,即:information_schem ...

  3. java网络爬虫基础学习(二)

    正则表达式 正则表达式写法 含义 \d 代表0-9的任意数字 \D 代表任何非数字字符 \s 代表空格类字符 \S 代表非空格类字符 \p{Lower} 代表小写字母[a-z] \p{Upper} 代 ...

  4. shader高级纹理学习总结

    最近看了shader的高级纹理 做个总结 复习! shader迟早是要拿下的

  5. python接口自动化-json数据处理

    前言 有些post的请求参数是json格式的,需要导入json模块进行处理,json是一种数据交换格式,独立于编程语言 一般常见的接口返回数据也是json格式的,我们在做判断的时候,往往只需要提取其中 ...

  6. tensorflow 训练之tensorboard使用

    1.add saclar and histogram tf.summary.scalar('mean', mean) tf.summary.histogram('histogram', var) 2. ...

  7. H5活动页开发有关

    活动页开发流程 针对各种节日各种活动,临时定稿开发的活动页,往往时间安排都比较急 ---- 产品定下需求方向 UI实现设计稿 1. 草图和交互逻辑定稿=>多少个页面,每个页面表达的含义以及和用户 ...

  8. 菜鸟学IT之简易四则运算程序开发

    作业要求来源:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/2166 作业要求: 任何编程语言都可以,命令行程序接受一个数字输入,然后 ...

  9. Stars project

    说明:收藏一些比较好的开源项目 Python实现了所有的排序算法 Github:https://github.com/TheAlgorithms/Python 该项目用Python实现了所有的排序算法 ...

  10. U68364 _GC滑迷宫

    题目背景 _GC买了一双蔡徐坤一代. 题目描述 _GC进入了一个n*m的迷宫.本题的特殊之处在于,_GC只能滑着走.具体来说就是,选定一个方向后,_GC会一直向该方向滑,直到撞到墙.会给出_GC的起始 ...