Home » Java » java.sql.SQLException: Statement has already been closed with spring simplejdbccall execute method [on hold]

java.sql.SQLException: Statement has already been closed with spring simplejdbccall execute method [on hold]

Posted by: admin July 12, 2018 Leave a comment

Questions:

I am getting below exception at a time of execute call of simplejdbccall.
Getting this error for some cases and not all.
After simplejdbccall execute method call, my procedure in DB is getting called and started execution but not finished execution and in between getting java.sql.SQLException: Statement has already been closed exception.
Below i have mentioned in detail.
I am using weblogic 12c Server.
My database procedure is taking around
3 – 4 minutes for execution and before execution get finished, somehow from server side statement is getting closed and throwing exception Statement has already been closed. But the thing is, it is not happening for all the cases. suppose for one case for which i got this error took 3 mins and for second case which also took 3 mins but did not get this error. i have set statement timeout property value to -1 which means disables statement timeout feature.

I have already checked many links including below links but did not find it helpful for my case.
statement has already been closed 1
statement has already been closed 2

@Service("testDao")
@Transactional(timeout = 300)
public class TestDaoImpl implements TestDao {
    @Autowired(required = true)
    private DataSource ds;
    @Autowired
    private JdbcTemplate jt;
    private SimpleJdbcCall simpleJdbcCall;
    public void setDataSource(DataSource ds) {
        this.ds = ds;
    }
    @Override
    public List < TestBean > Issue(
List < TestBean > data, HttpServletRequest req) {
        List < TestBean > ResponceList = new ArrayList < TestBean > ();
        String member_code = "";
        this.simpleJdbcCall = new SimpleJdbcCall(ds)
            .withSchemaName("TEST")
            .withCatalogName("TEST_PKG")
            .withProcedureName("TEST_DATA")
            .declareParameters(new SqlParameter("p_test_list", 
            OracleTypes.ARRAY, "TEST_LIST"),
                new SqlOutParameter("p_test_result_list", 
                OracleTypes.ARRAY, "TEST_RESULT_LIST"));
        Connection con = null;
        try {
            con = dataSource.getConnection();
            SqlParameterSource in = new MapSqlParameterSource()
                .addValue("p_test_list", arrayOfProjects, OracleTypes.ARRAY);
            Map < String, Object > out = simpleJdbcCall.execute( in );
            Array outlistObjectArray = (Array) out
                .get("p_test_result_list");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return ResponceList;
    }
}

Below mentioned is property set in weblogic
ServerPropertiesConfiguredImage 1
ServerPropertiesConfiguredImage 2

org.springframework.jdbc.UncategorizedSQLException:
CallableStatementCallback; uncategorized SQLException for SQL [{call
TEST.TEST_PKG.TEST_DATA(?, ?)}]; SQL state [null]; error code [0];
Statement has already been closed; nested exception is
java.sql.SQLException: Statement has already been closed
at
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:84)
at
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:1094)
at
org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:1130)
at
org.springframework.jdbc.core.simple.AbstractJdbcCall.executeCallInternal(AbstractJdbcCall.java:403)
at
org.springframework.jdbc.core.simple.AbstractJdbcCall.doExecute(AbstractJdbcCall.java:363)
at
org.springframework.jdbc.core.simple.SimpleJdbcCall.execute(SimpleJdbcCall.java:197)
at
com.test.web.daoImpl.TestDaoImpl.Issue(TestDaoImpl.java:239)
at
com.test.web.controllers.TestController.testSave(TestController.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606) at
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:111)
at
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:806)
at
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:729)
at
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:751) at
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:844) at
weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
at
weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
at
weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
at
weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:346)
at
weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:243)
at
weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3438)
at
weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3408)
at
weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at
weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at
weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
at
weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2280)
at
weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2196)
at
weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2174)
at
weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1621)
at
weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:256)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:311) at
weblogic.work.ExecuteThread.run(ExecuteThread.java:263) Caused by:
java.sql.SQLException: Statement has already been closed at
weblogic.jdbc.wrapper.Statement.checkStatement(Statement.java:335)
at
weblogic.jdbc.wrapper.Statement.preInvocationHandler(Statement.java:140)
at
weblogic.jdbc.wrapper.CallableStatement_oracle_jdbc_driver_OracleCallableStatementWrapper.getUpdateCount(Unknown
Source) at
org.springframework.jdbc.core.JdbcTemplate$6.doInCallableStatement(JdbcTemplate.java:1134)
at
org.springframework.jdbc.core.JdbcTemplate$6.doInCallableStatement(JdbcTemplate.java:1130)
at
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:1078)
… 40 more

Answers: