IDEA调试时Mapper访问数据库报错:CommunicationsException: The last packet successfully received

IDEA调试时Mapper访问数据库报错:CommunicationsException: The last packet successfully received

背景

很普通的一次调试,之前好像也遇到过,记录一下。
springboot mybatis

问题描述

IDEA debug模式启动,网络请求进入某service断点,手动单步一下下执行,在调用另一个service时报错,错误栈定位到其中的一个mapper接口,错误信息如下:

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 574,962 milliseconds ago.  The last packet sent successfully to the server was 574,962 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
### The error may exist in file [D:\...\mapper\AMapper.xml]
### The error may involve com.example.mapper.opt.getInfo-Inline
### The error occurred while setting parameters
### SQL: select 

利用计算器再次执行或是过长时间执行,则出现如下信息:

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 68886ms.
### The error may exist in file [D:\...\mapper\AMapper.xml]
### The error may involve com.example.mapper.opt.getInfo
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 68886ms.

分析

第一段信息里说了,距离上次请求数据的时间间隔,超过了服务器设定的“wait_timeout”等待超时时间,由于调试时间过长,导致数据库服务端连接超时断开,造成应用侧连接错误。

第二块信息可能是达到了数据库连接池连接的超时时间,导致连接失效。

这二者间具体原因的区别,有待考究,这里描述也不严谨,仅是根据错误信息推测。

解决方案

  • 点击继续运行按钮(debug窗口绿色三角),重新发送网络请求,重新调试。

超时报错可遇不可求,下面两种方法没有验证(ai助手给出,其实错误信息里提示了),遇到再说

  • 增加服务器配置的客户端超时时长,
  • 数据库连接中加入’autoReconnect=true’

声明:本文使用八爪鱼rpa工具从gitee自动搬运本人原创(或摘录,会备注出处)博客,如版式错乱请评论私信,如情况紧急或久未回复请致邮 xkm.0jiejie0@qq.com 并备注原委;引用本人笔记的链接正常情况下均可访问,如打不开请查看该链接末尾的笔记标题(右击链接文本,点击 复制链接地址,在文本编辑工具粘贴查看,也可在搜索框粘贴后直接编辑然后搜索),在本人博客手动搜索该标题即可;如遇任何问题,或有更佳方案,欢迎与我沟通!

HTTP Status 500 – Internal Server Error Type Exception Report Message Request processing failed; nested exception is org.springframework.dao.RecoverableDataAccessException: Description The server encountered an unexpected condition that prevented it from fulfilling the request. Exception org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.RecoverableDataAccessException: ### Error querying database. Cause: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure The last packet successfully received from the server was 805,518 milliseconds ago. The last packet sent successfully to the server was 805,557 milliseconds ago. ### The error may exist in mapper/UsersMapper.xml ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: SELECT * FROM users WHERE TRIM(code) = TRIM(?) ### Cause: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure The last packet successfully received from the server was 805,518 milliseconds ago. The last packet sent successfully to the server was 805,557 milliseconds ago. ; Communications link failure The last packet successfully received from the server was 805,518 milliseconds ago. The last packet sent successfully to the server was 805,557 milliseconds ago.; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure The last packet successfully received from the server was 805,518 milliseconds ago. The last packet sent successfully to the server was 805,557 milliseconds ago. org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) javax.servlet.http.HttpServlet.service(HttpServlet.java:635) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) javax.servlet.http.HttpServle
最新发布
03-08
springboot+MyBatis连接MySql数据库遇到问题:### Error querying database. Cause: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure The last packet successfully received from the server was 11,751 milliseconds ago. The last packet sent successfully to the server was 11,858 milliseconds ago. ### The error may exist in file [/app/tomcat/webapps/project/WEB-INF/classes/mapper/PersonWeekMapper.xml] ### The error may involve com.xmsme.mapper.PersonWeekMapper.selectPersonWeekList-Inline ### The error occurred while setting parameters ### SQL: SELECT count(0) FROM (SELECT WEEK.id, WEEK.sub_time, WEEK.need_thing, WEEK.plan_content, WEEK.target_content, WEEK.sub_time AS update_time, WEEK.create_time, WEEK.week_start, WEEK.user_id, WEEK.week_end, readInfo.id AS readId, readInfo.read_status AS readStatus, updateor.nick_name FROM t_person_weekly AS WEEK LEFT JOIN sys_user sUser ON sUser.user_id = WEEK.user_id LEFT JOIN t_read_info readInfo ON readInfo.business_id = WEEK.id AND readInfo.read_type = 'PER' LEFT JOIN sys_user updateor ON updateor.user_id = WEEK.update_by LEFT JOIN sys_user_role uRole ON uRole.user_id = WEEK.update_by LEFT JOIN sys_user_post uPost ON uPost.user_id = WEEK.user_id LEFT JOIN t_project_person person ON person.user_id = WEEK.user_id LEFT JOIN t_project_person Pperson ON Pperson.project_id = person.project_id WHERE 1 = 1 AND WEEK.is_del = 0 AND WEEK.draft = 'N' AND Pperson.user_id = ? GROUP BY WEEK.id) table_count ### Cause: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure The last packet successfully received from the server was 11,751 milliseconds ago. The last packet sent successfully to the server was 11,858 milliseconds ago. ; Communications link failure The last packet successfully received from the server was 11,751 milliseconds ago. The last packet sent successfully to the server was 11,858 milliseconds ago.; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure The last packet successfully received from the server was 11,751 milliseconds ago. The last packet sent successfully to the server was 11,858 milliseconds ago.
07-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值