lm20170824 2017-08-24 07:43 采纳率: 0%
浏览 13040

java中访问mysql 出现 communications link failure

项目中一条很简单的select 语句:select coulmn1,coulmn2,coulmn3 from table where coulmn1 != 2;
一直都没有问题,table中也就20来条数据,今天项目启起来忽然出现:

org.springframework.dao.RecoverableDataAccessException:

Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 1,000,128 milliseconds ago. The last packet sent successfully to the server was 1,000,129 milliseconds ago.

The error may exist in URL [jar:file:/D:/IDEA%20work/yohobuy-crm/web/target/yohobuy-crm-web/WEB-INF/lib/yohobuy-crm-dal-1.0.0-SNAPSHOT.jar!/META-INF/mybatis/PushTemplateMapper.xml]

The error may involve defaultParameterMap

The error occurred while setting parameters

SQL: SELECT content_type, push_template_id, push_template_title, push_template_content, push_template_herf, status, create_time, update_time, create_user_id,model_type,model_param FROM push_template WHERE status!=2

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

The last packet successfully received from the server was 1,000,128 milliseconds ago. The last packet sent successfully to the server was 1,000,129 milliseconds ago.
; SQL []; Communications link failure

The last packet successfully received from the server was 1,000,128 milliseconds ago. The last packet sent successfully to the server was 1,000,129 milliseconds ago.; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 1,000,128 milliseconds ago. The last packet sent successfully to the server was 1,000,129 milliseconds ago.
at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:98)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)
at com.sun.proxy.$Proxy20.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:198)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:119)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
at com.sun.proxy.$Proxy76.selectAllPushTemplate(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)

然后我把这句sql改成: select coulmn2, coulmn1,coulmn3 from table where e coulmn1
!= 2就可以。就是说这句sql稍微一点点改动就行,就是原来的不行,没理由啊,这是什么原因啊,大侠们有遇到的的吗?在线等!

  • 写回答

1条回答 默认 最新

  • Carrie_zzz 2017-08-24 08:38
    关注

    使用Connector/J连接MySQL数据库,程序运行较长时间后就会报以下错误:
    Communications link failure,The last packet successfully received from the server was *** millisecond ago.The last packet successfully sent to the server was *** millisecond ago。
    其中错误还会提示你修改wait_timeout或是使用Connector/J的autoReconnect属性避免该错误。
    ,大部分都是使用连接池方式时才会出现这个问题,短连接应该很难出现这个问题。这个问题的原因:
    mysql服务器默认的“wait_timeout”是28800秒即8小时,意味着如果一个连接的空闲时间超过8个小时,MySQL将自动断开该连接,而连接池却认为该连接还是有效的(因为并未校验连接的有效性),当应用申请使用该连接时,就会导致上面的报错。
    修改MySQL的参数,wait_timeout最大为31536000即1年,在my.cnf中加入:
    [mysqld]
    wait_timeout=31536000
    interactive_timeout=31536000
    重启生效,需要同时修改这两个参数。

    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大