org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 6,388 milliseconds ago. The last packet sent successfully to the server was 1,504 milliseconds ago.
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:240)
主要原因:上述问题是由mysql5数据库的配置引起的。mysql5将其连接的等待时间(wait_timeout)缺省为8小时。在其客户程序中可以这样来查看其值:
mysql﹥
mysql﹥ show global variables like 'wait_timeout';
+---------------+---------+
| Variable_name | Value |
+---------------+---------+
| wait_timeout | 28800 |
+---------------+---------+
1 row in set (0.00 sec)
28800 seconds,也就是8小时。
如果在wait_timeout秒期间内,数据库连接(java.sql.Connection)一直处于等待状态,mysql5就将该连接关 闭。这时,你的Java应用的连接池仍然合法地持有该连接的引用。当用该连接来进行数据库操作时,就碰到上述错误。
解决办法(优先尝试第三种方案):
(1)在jdbc连接url的配置中,你可以附上“autoReconnect=true”,但这仅对mysql5以前的版本起作用。
(2)既然问题是由mysql5的全局变量wait_timeout的缺省值太小引起的,我们将其改大就好了。
查看mysql5的手册,发现对wait_timeout的最大值分别是24天/365天(windows/linux)。以windows为 例,假设我们要将其设为21天,我们只要修改mysql5的配置文件“my.ini”(mysql5 installation dir),增加一行:wait_timeout=1814400 ,需要重新启动mysql5。
linux系统配置文件:/etc/my.cnf
(3)我们可以将数据库连接池的 validateQuery、testOnBorrow(testOnReturn)打开,这样在 每次从连接池中取出且准备使用之前(或者使用完且在放入连接池之前)先测试下当前使用是否好用,如果不好用,系统就会自动destory掉。
或者testWhileIdle项是设置是否让后台线程定时检查连接池中连接的可用性。
分享到:
相关推荐
Cause com.mysql.jdbc.exceptions.jdbc4.CommunicationsException The last packet successfully received from the server was 47,795,922 milliseconds ago. The last packet sent successfully to the server was...
1、写在开头 标题之前我想说一下Linux的mysql真的实在是太坑了。太坑了。总是会出现这样那样的你想不到的问题。崩溃了。首先来罗列一下我遇到过的...Cause:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorExcepti
com.baomidou.mybatisplus.core.exceptions.MybatisPlusException: Error:GlobalConfigUtils setMetaData Fail !
博文链接:https://zyx19920203.iteye.com/blog/2301226
1、Caused by: com.MySQL.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 56,201,339 milliseconds ago. The last packet sent successfully to the...
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user ''@'localhost' to database 'hibernate' at sun.reflect.NativeConstructorAccessorImpl.new
c-jdbc数据库集群中间件详细配置方案(mysql),可以同步使用多个数据库数据交换。
MyEclipse8.x 汉化 包括汉化语言包和汉化方法
CXXFLAGS="-O3 -felide-constructors -fno-exceptions -fno-rtti" cmake . -LH|more //CMake下查看MySQL的编译配置 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DEXTRA_CHARSETS=all make make ...
可以通过异常:Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Acc
可用包+源码;最新版nacos-server-1.2.0.tar.gz 支持mysql 8.0
解决:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after statement closed.
Caused by: org.apache.ibatis.exceptions.PersistenceException: Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested ...
4)....Added "--el_injectjcl", "--el_createjcl", and "--el_createdbg" command-line options for ecc32/emake to inject JEDI/JCL debug info, create .jdbg file, and create .dbg file (Microsoft debug format...
今天用execjs调用JS时,发现报错execjs._exceptions.ProgramError: ReferenceError: document is not defined 如图: 错误类型:文档对象未定义,解决方法,定义对象即可,习惯性定义变量嘛 var document ;? ...
Mybatis报错: org.apache.ibatis.exceptions.PersistenceException解决办法 一、问题描述 写好配置文件用JUnit进行测试,一运行就报错: org.apache.ibatis.exceptions.PersistenceException: ### Error querying ...
MySQL Connector/J is licensed under the GPL or a commercial license from MySQL AB. If you have licensed this product under the GPL, please see the COPYING file for more information. There are ...
问题 Table ‘zup.Domain_System’ doesn’t exist ...### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'zup.Domain_System' doesn't exist ; bad SQL grammar []; nested
郁闷啊,有时候不得不承认,无论是什么事,曾经是好的,到后边未必还是好的,不要拿曾经的种种来判断今天的结果, 前景:之前本地用jeecg(1.7版本)设计流程、发布流程、修改流程,所有的操作都是项目有汉字启动的,...