DataSourcePool Service returning null/closed connection

anuj_pathak1 14-01-2019

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( [day.commons.datasource.jdbcpool:1.0.24]

    at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement( [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.


DataSource dataSource = (DataSource)dataSourceService.getDataSource(this.defaultDataSource);" 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);"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?

Answers (5)

Answers (5)

anuj_pathak1 14-01-2019

thanks for response gaurav,

I think i looked at it before but if you look at here Adobe Experience Manager Help | Injecting a DataSourcePool Service into an Adobe Experience Manager ...  line # 115 of, they are closing connection in finally block but not in other DB calls like in  getCustomerData().