signed

QiShunwang

“诚信为本、客户至上”

No operations allowed after statement closed.

2021/4/26 17:43:21   来源:

解决:Cause: java.sql.SQLException: No operations allowed after statement closed.

因这个问题调试了一下午的debug,希望能给大家帮助。
最开始以为是 IOC 连接关闭问题,开启子线程问题之类的。

NO ,NO,NO 其实此处是线程池连接生命周期的问题。

ELK 都已经提示了我,因经验不足,写出来大家一起交流。总比一个人调试debug到🤮为止吧,欢迎留言交流,因为更细节的东西我无法解释,求大神告知,解决了却不知道为啥,也着实迷茫。
在这里插入图片描述

如果你遇到相关的问题,且DataSource是这样配置的,
你只需要设置成

   max-lifetime: 120000

在这里插入图片描述

日志整理

2021-04-26 17:22:20.659  WARN 14409 --- [           main] com.zaxxer.hikari.pool.ProxyConnection   : webPool - Connection com.mysql.jdbc.JDBC4Connection@5315210d marked as broken because of SQLSTATE(08003), ErrorCode(0)
  
Caused by: java.sql.SQLException: No operations allowed after statement closed.
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965) ~[mysql-connector-java-5.1.49.jar:5.1.49]
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898) ~[mysql-connector-java-5.1.49.jar:5.1.49]
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887) ~[mysql-connector-java-5.1.49.jar:5.1.49]
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:861) ~[mysql-connector-java-5.1.49.jar:5.1.49]
	at com.mysql.jdbc.StatementImpl.checkClosed(StatementImpl.java:426) ~[mysql-connector-java-5.1.49.jar:5.1.49]
	at com.mysql.jdbc.PreparedStatement.clearBatch(PreparedStatement.java:1051) ~[mysql-connector-java-5.1.49.jar:5.1.49]
	at com.mysql.jdbc.PreparedStatement.executeBatchInternal(PreparedStatement.java:1323) ~[mysql-connector-java-5.1.49.jar:5.1.49]
	at com.mysql.jdbc.StatementImpl.executeBatch(StatementImpl.java:954) ~[mysql-connector-java-5.1.49.jar:5.1.49]
	at com.zaxxer.hikari.pool.ProxyStatement.executeBatch(ProxyStatement.java:128) ~[HikariCP-3.4.5.jar:na]
	at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeBatch(HikariProxyPreparedStatement.java) ~[HikariCP-3.4.5.jar:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_261]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_261]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_261]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_261]
	at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:78) ~[mybatis-3.5.4.jar:3.5.4]
	at com.sun.proxy.$Proxy268.executeBatch(Unknown Source) ~[na:na]
	at com.baomidou.mybatisplus.core.executor.MybatisBatchExecutor.doFlushStatements(MybatisBatchExecutor.java:133) ~[mybatis-plus-core-3.3.2.jar:3.3.2]
	at org.apache.ibatis.executor.BaseExecutor.flushStatements(BaseExecutor.java:129) ~[mybatis-3.5.4.jar:3.5.4]
	at org.apache.ibatis.executor.BaseExecutor.flushStatements(BaseExecutor.java:122) ~[mybatis-3.5.4.jar:3.5.4]
	at com.baomidou.mybatisplus.core.executor.MybatisCachingExecutor.flushStatements(MybatisCachingExecutor.java:216) ~[mybatis-plus-core-3.3.2.jar:3.3.2]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_261]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_261]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_261]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_261]
	at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63) ~[mybatis-3.5.4.jar:3.5.4]
	at com.sun.proxy.$Proxy266.flushStatements(Unknown Source) ~[na:na]
	at org.apache.ibatis.session.defaults.DefaultSqlSession.flushStatements(DefaultSqlSession.java:252) ~[mybatis-3.5.4.jar:3.5.4]
	at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.lambda$executeBatch$3(ServiceImpl.java:258) ~[mybatis-plus-extension-3.3.2.jar:3.3.2]
	at com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.executeBatch(ServiceImpl.java:222) ~[mybatis-plus-extension-3.3.2.jar:3.3.2]
	... 78 common frames omitted

org.springframework.transaction.TransactionSystemException: Could not roll back JDBC transaction; nested exception is java.sql.SQLException: Connection is closed