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.
dataSourceService=dataSourceService!=null?dataSourceService:getFromBundle();
DataSource dataSource = (DataSource)dataSourceService.getDataSource(this.defaultDataSource);
logger.info(" getConnection dataSource= "+dataSource); // here i can see not null value in log file
this.connection = this.connection!=null?this.connection:(dataSource!=null?dataSource.getConnection():null);
logger.info("data source connection= "+connection); //null value printed here in log file
Do we need to remove connection.close(); calls which we added as best practice or it has something to with pool service OSGI config?