1

I am using JNDI configuration with JDBCtemplate as autowired in spring boot application.

Connection is creating successfully. But when we execute save or search operation it gets failed with below error:

org.springframwwork.dao.RecoverableDataAccessException: CallableStatementCallback; SQL [] Closed Connection ; nested exception is java.sql.SQLRecoverableException: Closed Connection

I have tried below stackoverflow solution as well but it doesn't worked.

What is the cause of "RecoverableDataAccessException" received when checking health of database?

Please find the below context.xml configuration used for the connection:

<Resource name="jdbc/xyz" 
auth="Container" 
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
url=""
username="" 
password=""
minActive="30" 
maxActive="100" 
minIdle="10" 
maxIdle="10" 
initialSize="10"
jmxEnabled="true" 
timeBetweenEvictionRunsMillis="30000"
minEvictableIdleTimeMillis="30000" 
maxWait="10000" 
logAbandoned="true"
testOnBorrow="true" 
testOnConnect="false" 
suspectTimeout="120"
validationQuery="select 1 from dual" 
validationInterval="30000"
initSQL="select 1 from dual" 
removeAbandoned="true"
removeAbandonedTimeout="60" 
maxAge="180000"
accessToUnderlyingConnectionAllowed="true">
</Resource>

Tried changing the maxWait to -1 in context.xml as well.

JdbcTemplate is getting autowired successfully. Mostly search operations are working fine but when we do save operation its getting failed with SQLRecoverableException as mentioned above.

I am creating SimpleJdbcCall object using jdbcTemplate object and then executing it as to save the details in oracle database.

SimpleJdbcCall save = new SimpleJdbcCall(jdbcTemplate).withProcedureName("xxpqr_abc")
.withCatalogName("xxpqr__xx_abc").withoutProcedureColumnMetaDataAccess()
.declareParameters(new SqlParameter("abc", OracleTypes.ARRAY, "abc1"),
new SqlParameter("xyz", OracleTypes.ARRAY, "xyz1"),
new SqlOutParameter("error_msg", Types.VARCHAR));

Map<String, Object> saveResult = save.execute(
new MapSqlParameterSource().addValue("pqr", new SqlArrayValue(empDetailsArray))
.addValue("pqr", saveObj.getSubmitFlag())); 

During execute got the java.lang.NullPointerException.

Same operation is working fine if connection created using spring @configuration annotation using separate class. But that doesn't provide connection pooling.

Vishal
  • 127
  • 1
  • 2
  • 16
  • Issue is resolved when did the entire setup as fresh, it might with issue with the server which is closing the db connection. – Vishal Feb 14 '19 at 17:42

0 Answers0