background
mybatis is used only, but spring is not used because it involves multiple data sources, so each query uses the mapper factory method to create mappers to execute select or Update.
Executor was closed when the same mapper executed select and executed update.
Solve
Log
2018-05-30 17:09:58,941 DEBUG [org.apache.ibatis.transaction.jdbc.JdbcTransaction] - Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@2a9650c7]
2018-05-30 17:09:58,941 DEBUG [org.apache.ibatis.datasource.pooled.PooledDataSource] - Returned connection 714494151 to pool.
It can be seen that the connection is returned to the connection pool after the query is executed, and the error will be reported if the query is used again.
At present, my approach is to create a connection by query, and then create another connection before executing update.
ChannelsInstallmentLederMapper channelsInstallmentLederMapper = MapperFactory.createMapper(ChannelsInstallmentLederMapper.class, (String) Constant.DATA_SOURCE.get(dataSource));
// query
List<ChannelsInstallmentLeder> channelsInstallmentLeders = channelsInstallmentLederMapper.selectByOrderIdAndPeriod(orderId, period);
// To update
for (ChannelsInstallmentLeder channelsInstallmentLeder:channelsInstallmentLeders) {
channelsInstallmentLederMapper = MapperFactory.createMapper(ChannelsInstallmentLederMapper.class, (String) Constant.DATA_SOURCE.get(dataSource));
channelsInstallmentLeder.setCollectdate(new Date());
channelsInstallmentLederMapper.updateByPrimaryKey(channelsInstallmentLeder);
}
2018-05-30 17:09:58,941 DEBUG [org.apache.ibatis.transaction.jdbc.JdbcTransaction] - Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@2a9650c7]
2018-05-30 17:09:58,941 DEBUG [org.apache.ibatis.datasource.pooled.PooledDataSource] - Returned connection 714494151 to pool.
2018-05-30 17:09:58,941 DEBUG [org.apache.ibatis.transaction.jdbc.JdbcTransaction] - Opening JDBC Connection
2018-05-30 17:09:58,941 DEBUG [org.apache.ibatis.datasource.pooled.PooledDataSource] - Checked out connection 714494151 from pool.
If you have a better way to do it, don't hesitate to give advice.