Oracle ucp jdbc池无法在tomcat 6至8升级中工作

时间:2018-10-20 12:08:41

标签: java oracle tomcat jdbc ojdbc

我们试图通过代码创建oracle数据源和连接池。 我们正在使用ojdbc6.jar

Context ctx = null;
    Properties cacheProperties = new Properties();

    System.out.println( ">>>>>>>> Initializing the ORACLE datasource and connection pool <<<<<<<<<" );

    // JNDI parameters
    String oracle_dataSource = "mfc:mfcJdbcDatasource";

    // DataSource parameters
    String username = "admin";
    String password = "password";

    String url = "jdbc:oracle:thin:@server details";
    String ods_ONSConfiguration = "<onsconfigruation>";

    String ods_driverClassName = "oracle.jdbc.driver.OracleDriver";
    boolean ods_ConnectionCachingEnabled = true;
    boolean ods_FastConnectionFailoverEnabled = true;
    boolean ods_ValidateConnectionOnBorrow = true;
    String ods_ConnectionCacheName = "ConnectionCache";
    boolean ods_UCPMgrEnabled = true;

    // Connection Cache properties
    String ods_InitialLimit = "5";
    String ods_MinLimit = "1";
    String ods_MaxLimit = "50";
    String ods_ConnectionWaitTimeout = "2000";
    String ods_AbandonedConnectionTimeout = "900";
    String ods_MaxStatementsLimit = "40";
    String ods_PropertyCheckInterval = "900";
    String ods_InactivityTimeout = "28800";

    cacheProperties.setProperty( "InitialLimit", ods_InitialLimit );
    cacheProperties.setProperty( "MinLimit", ods_MinLimit );
    cacheProperties.setProperty( "MaxLimit", ods_MaxLimit );
    cacheProperties.setProperty( "ConnectionWaitTimeout", ods_ConnectionWaitTimeout );
    cacheProperties.setProperty( "AbandonedConnectionTimeout", ods_AbandonedConnectionTimeout );
    cacheProperties.setProperty( "MaxStatementsLimit", ods_MaxStatementsLimit );
    cacheProperties.setProperty( "PropertyCheckInterval", ods_PropertyCheckInterval );
    cacheProperties.setProperty( "InactivityTimeout", ods_InactivityTimeout );

    System.out.println( "Initializing Oracle connection pool with following parameters: " + "\n\t url: " + url + "\n\t username: " + username + "\n\t driverClassName: " + ods_driverClassName + "\n\t ConnectionCachingEnabled: " + ods_ConnectionCachingEnabled + "\n\t FastConnectionFailoverEnabled: " + ods_FastConnectionFailoverEnabled + "\n\t ConnectionCacheName: " + ods_ConnectionCacheName + "\n\t ONSConfiguration: " + ods_ONSConfiguration + "\n\t cacheProperties: " + cacheProperties );

    // First load Oracle driver
    try {
        Class.forName( ods_driverClassName );
    }
    catch ( ClassNotFoundException e ) {
        e.printStackTrace();
        System.out.println( "Unable to load database driver: " + ods_driverClassName );
    }

    try {
        // initialize oracle datasource

        PoolDataSource datasource = PoolDataSourceFactory.getPoolDataSource();

        if ( ods_UCPMgrEnabled ) {

            UniversalConnectionPoolManager mgr = UniversalConnectionPoolManagerImpl.getUniversalConnectionPoolManager();
            mgr.setLogLevel( Level.FINE );
        }

        datasource.setURL( url );
        datasource.setUser( username );
        datasource.setPassword( password );

        datasource.setConnectionFactoryClassName( "oracle.jdbc.pool.OracleDataSource" );

        datasource.setONSConfiguration( ods_ONSConfiguration );

        datasource.setFastConnectionFailoverEnabled( ods_FastConnectionFailoverEnabled );
        datasource.setValidateConnectionOnBorrow( ods_ValidateConnectionOnBorrow );

        datasource.setConnectionPoolName( ods_ConnectionCacheName );

        datasource.setConnectionProperties( cacheProperties );

        ctx = new InitialContext();
        ctx.bind( oracle_dataSource, datasource );
    }

当我们试图像这样从池中获取数据库连接时。

Connection c = null;
        PoolDataSource ds = null;

        try {
            ds = (PoolDataSource)ctx.lookup("mfc:mfcJdbcDatasource");

            c = ds.getConnection();
        } catch (Exception e) {
            try {
                if (c != null) c.close();
            }catch (Exception e1) {
            }
            /*try {
                OracleJDBCConnectionPoolStatistics stats = (OracleJDBCConnectionPoolStatistics) ds.getStatistics();
                DAUtil.perror("Connection Pool Stats on Error: " + stats.getFCFProcessingInfo(), DBTransactionalManager.class, MSG_TYPE.ERROR);                     
            } catch (Exception e1) {            
            }*/
            c = null;
            e.printStackTrace();
        }
        return c;

上面的代码在tomcat 6中工作正常。 但是当我们将战争部署在tomcat 8上时,尝试再次访问它时会引发以下错误。

2018年10月20日下午3:05:51 oracle.ucp.jdbc.PoolDataSourceImpl createPoolWithDefaultProperties FINE:使用默认属性创建连接池实例 java.sql.SQLException:无法启动通用连接池:oracle.ucp.UniversalConnectionPoolException:在通用连接池管理器MBean中创建池期间出错     在oracle.ucp.util.UCPErrorHandler.newSQLException(UCPErrorHandler.java:541)     在oracle.ucp.jdbc.PoolDataSourceImpl.throwSQLException(PoolDataSourceImpl.java:588)     在oracle.ucp.jdbc.PoolDataSourceImpl.startPool(PoolDataSourceImpl.java:277)     在oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:647)     在oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:614)     在oracle.ucp.jdbc.PoolDataSourceImpl.getConnection(PoolDataSourceImpl.java:608)     在com.testojb.example.DBTransactionalManager $ DBAccess.getConnection(DBTransactionalManager.java:71)     在com.testojb.example.DBTransactionalManager处。(DBTransactionalManager.java:101)     在com.testojb.example.DBTransactionalManager.getInstance(DBTransactionalManager.java:111)     在com.testojb.example.HelloWorld.doGet(HelloWorld.java:44)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:635)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:742)     在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)     在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)     在org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)     在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)     在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)     在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)     在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)     在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496)     在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)     在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)     在org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)     在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)     在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)     在org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)     在org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)     在org.apache.coyote.AbstractProtocol $ ConnectionHandler.process(AbstractProtocol.java:790)     在org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1468)     在org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)     在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)     在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:624)     在org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)     在java.lang.Thread.run(Thread.java:748) 由以下原因引起:oracle.ucp.UniversalConnectionPoolException:在通用连接池管理器MBean中创建池期间出错     在oracle.ucp.util.UCPErrorHandler.newUniversalConnectionPoolException(UCPErrorHandler.java:421)     在oracle.ucp.util.UCPErrorHandler.newUniversalConnectionPoolException(UCPErrorHandler.java:389)     在oracle.ucp.admin.UniversalConnectionPoolManagerMBeanImpl.createConnectionPool(UniversalConnectionPoolManagerMBeanImpl.java:360)     在oracle.ucp.jdbc.PoolDataSourceImpl.startPool(PoolDataSourceImpl.java:252)     ...另外31个 由以下原因引起:oracle.ucp.UniversalConnectionPoolException:在通用连接池管理器中创建池期间出错     在oracle.ucp.util.UCPErrorHandler.newUniversalConnectionPoolException(UCPErrorHandler.java:421)     在oracle.ucp.util.UCPErrorHandler.newUniversalConnectionPoolException(UCPErrorHandler.java:389)     在oracle.ucp.admin.UniversalConnectionPoolManagerBase.createConnectionPool(UniversalConnectionPoolManagerBase.java:575)     在oracle.ucp.admin.UniversalConnectionPoolManagerMBeanImpl.createConnectionPool(UniversalConnectionPoolManagerMBeanImpl.java:347)

0 个答案:

没有答案