Caused by: java.sql.SQLException: Couldn't perform the operation getAutoCommit: You can't perform any operations on this connection. It has been automatically closed by Proxool for some reason (see lo

时间:2022-08-05 15:25:59

系统启动,一段时间不操作,然后在来操作时,报错如下:

Caused by: java.sql.SQLException: Couldn't perform the operation getAutoCommit: You can't perform any operations on this connection. It has been automatically closed by Proxool for some reason (see logs).
at org.logicalcobwebs.proxool.WrappedConnection.invoke(WrappedConnection.java:207)
at org.logicalcobwebs.proxool.WrappedConnection.intercept(WrappedConnection.java:87)
at $java.lang.AutoCloseable$$EnhancerByProxool$$48e70053.getAutoCommit(<generated>)
at org.hibernate.jdbc.ConnectionManager.isAutoCommit(ConnectionManager.java:212)
at org.hibernate.jdbc.JDBCContext.afterNontransactionalQuery(JDBCContext.java:266)
... 50 more

原因很简单:

mysql的数据库链接的生命周期有个时间限制,超过了时间mysql会关闭连接,这个关闭操作数据库连接池是不知道的,所以使用数据库链接时需要进行测试

修改Proxool相关配置即可:

<!--使用前先进行测试-->
<property name="testBeforeUse" value="true" />

<!--使用后执行关闭操作前先进行测试-->
<property name="testAfterUse" value="true" />

<!--用于保持连接的测试语句 -->

<property name="houseKeepingTestSql" value="select CURRENT_DATE" />

<!--日志统计跟踪类型-->
<property name="statisticsLogLevel" value="ERROR" />

<!--表示连接的最大活动时间, 如果到某个线程的活动时间大于这个数值,将会杀掉这个线程。默认是5分钟。-->
<property name="maximumActiveTime" value="${maximumActiveTime}" />