ÃֽŠ°Ô½Ã±Û(OS/WAS)
2023.12.18 / 13:47

How to: fix exception java.sql.SQLException: Already closed.

XMaLL°ü¸®ÀÚ
Ãßõ ¼ö 21

Problem Statement:

When we add some columns in the AdHoc Report , application throws the error "already closed" with no more information given.


Solution Explanation:

This error appears randomly and disappears without doing anything in the same session.

For example, I try to insert an object three times with an error, and the fourth time it works fine.

Quoting the stack trace from jasperserver.log file that was related to this behavior:

2014-10-02 20:06:48,831 ERROR BaseJdbcDataSource,http-apr-8080-exec-3:62 - Error closing connection.java.sql.SQLException: Already closed.at org.apache.commons.dbcp.PoolableConnection.close(PoolableConnection.java:77)at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close(PoolingDataSource.java:180)at com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.BaseJdbcDataSource.closeConnection(BaseJdbcDataSource.java:57)at com.jaspersoft.commons.semantic.impl.DataSourceResolverImpl.closeDataSourceServices(DataSourceResolverImpl.java:88)at com.jaspersoft.ji.adhoc.strategy.CommonDomainDataStrategy.getWorkingDataSet(CommonDomainDataStrategy.java:1164)[/code]

This problem was related to the incorrect configuration of JasperReports Server (and all other JNDI¡¯s) in this environment.

Quoting the incorrect configuration:

<Resource name="jdbc/jasperserver"          auth="Container"          type="javax.sql.DataSource"          maxActive="100"          maxIdle="30"          maxWait="10000"          username="postgres"          password="postgres"          driverClassName="org.postgresql.Driver"          accessToUnderlyingConnectionAllowed="true"          testOnBorrow="true"          url="jdbc:postgresql://localhost:5432/jasperserver"          factory="com.jaspersoft.jasperserver.tomcat.jndi.JSBasicDataSourceFactory" />[/code]

and the default configuration:

<Resource name="jdbc/jasperserver"          auth="Container"          type="javax.sql.DataSource"          maxActive="100"          maxIdle="30"          maxWait="10000"          username="jasperdb"          password="password"          driverClassName="org.postgresql.Driver"          validationQuery="SELECT 1"          testOnBorrow="true"          url="jdbc:postgresql://127.0.0.1:5432/jasperserver?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&autoReconnectForPools=true"          factory="com.jaspersoft.jasperserver.tomcat.jndi.JSBasicDataSourceFactory" />[/code]

Please use the recommended settings to avoid such behavior.