当前位置: 首页 > 面试题库 >

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链接失败软件导致连接中止:recv失败

严项明
2023-03-14
问题内容

我已经遇到了几天的问题,这是详细信息堆栈信息:

org.springframework.dao.RecoverableDataAccessException: 
### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 18,940 milliseconds ago.  The last packet sent successfully to the server was 18,918 milliseconds ago.
### The error may involve com.tuan800.searchtask.model.dao.mybatis.RelationDao.updateSuggest-Inline
### The error occurred while setting parameters
### Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 18,940 milliseconds ago.  The last packet sent successfully to the server was 18,918 milliseconds ago.
; SQL []; Communications link failure

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

The last packet successfully received from the server was 18,940 milliseconds ago.  The last packet sent successfully to the server was 18,918 milliseconds ago.
    at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:98)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:71)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:346)
    at $Proxy10.update(Unknown Source)
    at org.mybatis.spring.SqlSessionTemplate.update(SqlSessionTemplate.java:245)
    at com.tuan800.searchtask.model.dao.mybatis.impl.RelationDaoImpl.updateSuggest(RelationDaoImpl.java:24)
    at com.tuan800.searchtask.service.impl.RelationServiceImpl.modifyRelationCount(RelationServiceImpl.java:64)
    at com.tuan800.searchtask.RelationIndexTask.main(RelationIndexTask.java:33)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:115)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 18,940 milliseconds ago.  The last packet sent successfully to the server was 18,918 milliseconds ago.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1118)
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3055)
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2941)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3489)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2113)
    at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1364)
    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:989)
    at sun.reflect.GeneratedMethodAccessor163.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:45)
    at $Proxy20.execute(Unknown Source)
    at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:22)
    at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:51)
    at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:29)
    at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:88)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:121)
    at sun.reflect.GeneratedMethodAccessor165.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:338)
    ... 10 more
Caused by: java.net.SocketException: Software caused connection abort: recv failed
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:129)
    at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:114)
    at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:161)
    at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:189)
    at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2499)
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2952)
    ... 32 more

我想通过mybatis和spring更新mysql中的一条记录,然后一个接一个地更新它,下面是mybatis config:更新建议集count =#{count},version =#{version},freq =#{freq}其中id =#{id}

以及服务代码

for(RelationBvo relation : list){

       Long totalCount = solrDealService.queryResult(relation.getWord(),null,null,0);

       relation.setCount(totalCount.intValue());

       if(relation.getFreq() == 0){
            relation.setFreq(1);
       }

       ***relationDao.updateSuggest(relation);//update record***

       executedCount++;

       logger.info("Program have executed "+executedCount+" records.");
}

有人可以帮我吗?非常感谢。


问题答案:

你的mySQL连接在连接池识别它们之前已超时。有多种解决方法:

  1. 增加mysql配置文件(my.ini)中的超时值
  2. 减少连接池中的空闲时间,以便在mysql关闭连接之前将其丢弃
  3. 在你的池配置中添加一个验证连接查询,以便该池在将每个连接提供给你之前对其进行测试,但这会严重降低系统速度。


 类似资料:
  • 问题内容: 这个问题已经在这里有了答案 : “软件导致连接中止:套接字写入错误”的官方原因 (14个答案) 3年前关闭。 所有。我已经遇到了几天的问题,这是详细信息堆栈信息: 我想通过mybatis和spring更新mysql中的一条记录,然后一个接一个地更新它,下面是mybatis config:更新建议集count =#{count},version =#{version},freq =#{f

  • 问题内容: 我正在努力使数据库与Java程序进行通讯。 有人可以使用JDBC给我一个快速而肮脏的示例程序吗? 我收到一个非常严重的错误: 测试文件的内容: 问题答案: 所以,你有一个 com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:通信链接失败 java.net.ConnectException:连接被拒绝 我引用了这个答案,其中还包

  • 我正在使用hibernate.cfg运行Spring MVC应用程序,如下所示: 当我在本地环境中运行应用程序时,它运行起来没有任何问题。但在服务器上,它给出的异常为:

  • 下面是我用于所有MySQL连接的代码: 然后与数据库交互,我使用以下格式:

  • 问题内容: 我使用Java从Mysql查询一些记录。但是在某些持续时间的查询中,我遇到了使查询失败的问题,而在其他查询中,它查询成功了。错误消息是下一个: 我尝试了一些方法,例如: 设置 在 添加 到我的连接网址 但什么也没发生。 我的环境是: Mysql:5.5.3-m3-log源代码分发 的Java:1.6.0_16 JDK:HotSpot(TM)64位服务器VM(内部版本14.2-b01,混

  • 问题内容: 我正在使用Mac OS X Lion版本10.8。我通过XAMPP安装了MySQL。并且我已经将mysql和jdbc驱动程序(5.1.22)添加到了我的类路径中。以下简单代码无法正常工作: 运行代码时,出现以下错误: 有谁知道如何解决这个问题? 问题答案: 我终于弄明白了。感谢Max和Yogendra发布。问题出在我的XAMPP配置上。要解决此问题,我做了如下操作: 然后我运行我的代码