创建“连接缓存中找到的无效或过时连接”本地Oracle数据库

时间:2013-05-20 22:37:52

标签: sql oracle exception jdbc

我想知道如何调整我的本地Oracle数据库设置以通过我的Web应用程序获取此错误。任何意见都将不胜感激。

感谢。 我修改了用户的个人资料:

ALTER PROFILE cashnet LIMIT 
    SESSIONS_PER_USER          UNLIMITED 
    CPU_PER_SESSION            UNLIMITED 
    CPU_PER_CALL               3000 
    CONNECT_TIME               1 
    IDLE_TIME                  1
    LOGICAL_READS_PER_SESSION  DEFAULT 
    LOGICAL_READS_PER_CALL     1000 
    PRIVATE_SGA                15K
    COMPOSITE_LIMIT            5000000;

protected Properties getDefaultConnectionProps()
{
    Properties prop = new Properties ();`
    prop.setProperty("MinLimit", "1");     // the cache size is 5 at least 
    prop.setProperty("MaxLimit", "1");
    prop.setProperty("InitialLimit", "2"); // create 3 connections at startup
    prop.setProperty("InactivityTimeout", "1");    //  seconds
    prop.setProperty("TimeToLiveTimeout","30"); 
    prop.setProperty("AbandonedConnectionTimeout", "900");  //  seconds
    prop.setProperty("MaxStatementsLimit", "10");
    prop.setProperty("ValidateConnection","true");
    prop.setProperty("PropertyCheckInterval", "60"); // seconds
    System.out.println("[OracleConnector2.getDefaultConnectionProps] Setting properties");
    prop.setProperty("oracle.net.READ_TIMEOUT", "1");
    return prop;
}

public Connection getConnection() throws SQLException
{
    OracleConnectionPoolDataSource ocpds
        = (OracleConnectionPoolDataSource)_pooledConnections.get(getConectionId());
    if(ocpds == null){
        ocpds = new OracleConnectionPoolDataSource();
        ocpds.setURL(_url);
        ocpds.setUser(_user);
        ocpds.setPassword(_password);
        Properties prop = getDefaultConnectionProps();
        if (_readtimeout != null){
            _connectionProps.setProperty("oracle.jdbc.ReadTimeout", _readtimeout + "000");
        }
        else{
            _connectionProps.setProperty("oracle.jdbc.ReadTimeout", "20000");
        }
        // clean up connection props for OAS
        _connectionProps.remove("oracle.net.encryption_client");
        _connectionProps.remove("oracle.net.encryption_types_client");
        _connectionProps.remove("oracle.net.crypto_checksum_client");
        _connectionProps.remove("oracle.net.crypto_checksum_types_client");
        prop.putAll(_connectionProps);
        ocpds.setConnectionCacheProperties (prop);  // set properties
        _pooledConnections.put(getConectionId(),ocpds);
    }
    System.out.println("[OracleConnector2.getConnection] Setting timeout");
    if (_logintimeout != null){
        ocpds.setLoginTimeout(Integer.parseInt(_logintimeout.trim()));
    }else{
        ocpds.setLoginTimeout(10);
    }
    PooledConnection pc = ocpds.getPooledConnection(_user,_password);
    return pc.getConnection();
}

1 个答案:

答案 0 :(得分:0)

有各种方法。最简单的方法是终止当前连接池中的连接的数据库会话。如果由于某种原因,您希望强制该错误持续发生,我想您可以modify the profile为Oracle数据库用户设置IDLE_TIME(假设您的应用程序保持连接在连接池一段合理的时间)。