在使用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. vue(4)—— vue的过滤器,监听属性,生命周期函数,获取DOM元素

    过滤器 vue允许自定义过滤器,我个人认为,过滤器有两种,一种是对数据的清洗过滤,一种是对数据切换的动画过滤 数据切换的动画过滤 这里还是利用前面的动态组件的例子: 这里由于没办法展示动画效果,代码如 ...

  2. 【转】分享JavaScript监听全部Ajax请求事件的方法

    若Ajax请求是由jQuery的$.ajax发起的,默认情况下可以使用 jQuery的Global Ajax Event Handlers监听到Ajax事件,然而我遇到的却是用原生JavaScript ...

  3. maven笔记学习

    一.修改setting.xml文件中的镜像 在导入他人项目或者在导入项目时,我们会出现在项目中不能识别maven配置的库文件的情况那么我们可以重新下载本地库, 首先我们可以修改我们安装的maven环境 ...

  4. python面试终极准备

    简述Python的深浅拷贝? 将列表内的元素,根据位数合并成字典 lst = [1,2,4,8,16,32,64,128,256,512,1024,32769,65536,4294967296] # ...

  5. JS JSON对象相关

    1.多对象合并 将2个或2个以上对象(object{....})中的属性进行合并,即最后合并为一个object{.....} 解决办法:Object.assign 方法 var form = {nam ...

  6. mysql 小结

    Mariadb proxy maxscale01.test.com maxscale02.test.com Mariadb Galera Cluster db01.test.com db02.test ...

  7. mysql-笔记-datetime

    1 adddate(date,interval expr unit)--同 date_add() select date_add('2019-4-20',interval 31 day); selec ...

  8. LODOP打印超过后隐藏内容样式

    Lodop中的有纯文本和超文本,纯文本本身超过设置的打印项宽度,如果高度足够,就会换行,如果高度设置的很小,不会换行,后面的内容会直接隐藏.除非设置了多页项等,会自动分页.超文本打印项需要用css样式 ...

  9. react 事件绑定 es5/es6

    // vscode shift + ctrl + v 预览 es 5 写法 无参函数的绑定 first methods 定义函数: handleClick(e) { // e - 事件对象 e.pre ...

  10. Nginx HTTP变量原理

    L:72 首先如何获取url追加参数值 如: http://www.xxx.com?a=1&b=2 return '$arg_a, $arg_b'; #通过前缀 arg_a 就能获取到 参数a ...