To connect to mysql database, we defined JDBC pool service using which we are reading datasource and getting connection to read /write data.
In the back java code finally block, we are doing connection.close(); when we are done with everything but now we are running into issue where its complaining about connection is closed or returning null connection object.
caused by: java.sql.SQLException: Connection is closed.
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.checkOpen(PoolingDataSource.java:175) [day.commons.datasource.jdbcpool:1.0.24]
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:301) [day.commons.datasource.jdbcpool:1.0.24]
before this exception, below is block of code from which i can see datasource is not null but dataSource.getConnection() call is returning null value along with above exception.
If you are injecting DataSourcePoolService then you don't need to manage the boiler plate code to open/close the connection in your code which is the recommended way. The container would handle the lifecycle of service/connections.