Tomcat JDBC池配置

时间:2018-08-10 09:45:14

标签: java tomcat jdbc tomcat8 ojdbc

在UAT和PROD的某些环境中,但在SIT中,我面临一个奇怪的问题。对我来说,这似乎是与配置有关的问题。尽管所有设置,配置验证都相同。

在尝试使用while (rs.next())循环结果集时,获取“ Closed Statement:next” SQLException。

下面提供了代码段,错误堆栈跟踪和版本详细信息。

现有代码:

import org.apache.lucene.index.IndexWriter;

@SuppressWarnings("deprecation")
@Transactional(propagation = Propagation.REQUIRED)
private boolean fetchAndInsertData(final String indexType, final IndexWriter indexWriter) throws Exception {

    logger.info("Entering fetchAndInsertData()");

    Transaction tx = null;
    boolean success = false;
    CallableStatement callstmt = null;
    ResultSet rs = null;
    try {
        tx = this.getCurrentSession().beginTransaction();

        callstmt = this.getCurrentSession().connection().prepareCall("{call GET_VAL_PROC(?,?)}");
        callstmt.setString(1, indexType);
        callstmt.registerOutParameter(2, OracleTypes.CURSOR);

        callstmt.execute();

        rs = (ResultSet) callstmt.getObject(2);
        rs.setFetchSize(5000);

        logger.info("Resultset:"+ rs);

        while (rs.next()) {
            indexWriter.addDocument(convertResultToDoc(rs));
        }
        success = true;

    }  catch(SQLException e){
        logger.error("Error in SQL execute", e);
        success = false;
        tx.commit();
        return success;
     } catch (final Exception e) {
        logger.error("Getting Exception", e);            
        success = false;
    } finally {
        tx.commit();
    }
    logger.info("Exiting fetchAndInsertData()");
    return success;
}

private Document convertResultToDoc(ResultSet results) throws SQLException {
    final Document doc = new Document();
    final String resultKey = results.getString(1) != null ? results.getString(1).toString() : null;
    final String resultValue = results.getString(2) != null ? results.getString(2).toString() : null;
    doc.add(new TextField("resultKey", resultKey, Field.Store.YES));
    doc.add(new TextField("resultValue", resultValue, Field.Store.YES));
    return doc;
}

错误堆栈跟踪:

    java.sql.SQLException: Closed Statement: next
    at 
    oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
    at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
    at 
    oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:199)
    at 
    oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:263)
    at 
    oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:271)
    at oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java:205)
    at com.ville.dao.SomeDaoImpl.fetchAndInsertData(SomeDaoImpl.java:263)
    at com.ville.dao.SomeDaoImpl.createIndex(SomeDaoImpl.java:227)
    at com.ville.dao.SomeDaoImpl.getDetails(SomeDaoImpl.java:375)
    at com.ville.service.ServiceImpl.serviceCreateIndex(ServiceImpl.java:32)
    at com.ville.service.WSControl.controlCreateIndex(WSControl.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:781)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.ville.filter.MultiRequestWrapperFilter.doFilter(MultiRequestWrapperFilter.java:30)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.ville.filter.HttpInterceptorFilter.doFilter(HttpInterceptorFilter.java:36)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1103)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1477)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
2018-07-13 07:02:56 INFO  [http-nio-21290-exec-3] SomeDaoImpl - Exiting SomeDaoImpl.fetchAndInsertData()
2018-07-13 07:02:56 ERROR [http-nio-21290-exec-3] GlobalDefaultExceptionHandler - RestError [status=500, id=-1, message=Transaction not successfully started, developerMessage=org.hibernate.TransactionException: Transaction not successfully started
    at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:127)
    at com.ville.dao.SomeDaoImpl.fetchAndInsertData(SomeDaoImpl.java:281)
    at com.ville.dao.SomeDaoImpl.createIndex(SomeDaoImpl.java:227)
    at com.ville.dao.SomeDaoImpl.getDetails(SomeDaoImpl.java:375)
    at com.ville.service.ServiceImpl.serviceCreateIndex(ServiceImpl.java:32)
    at com.ville.service.WSControl.controlCreateIndex(WSControl.java:69)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:781)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.ville.filter.MultiRequestWrapperFilter.doFilter(MultiRequestWrapperFilter.java:30)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.ville.filter.HttpInterceptorFilter.doFilter(HttpInterceptorFilter.java:36)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1103)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1477)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

版本详细信息:

Tomcat版本:8.0.18_1
JRE:1.8.0_111l64
带有JDBC的OJDBC6.jar:11.1.0.7.0-生产
Oracle DB版本:Oracle Database 11g企业版11.2.0.4.0版-64位生产

context.xml中的现有配置

Resource name="jdbc/SomeDS"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@DbUrlWithPortNameEtc"
username="***"
password="********"
connectionProperties="SetBigStringTryClob=true"
accessToUnderlyingConnectionAllowed="true"
maxTotal="30"
maxIdle="10"
initialSize="5"
maxWaitMillis="180000"

0 个答案:

没有答案