1
votes

I am using Oracle UCP JDBC, and the following method is for getting a connection from a connection pool.

private static PoolDataSource poolDataSource;

....

static synchronized Connection createConnection() throws SQLException {
    if (poolDataSource == null) {
        poolDataSource = PoolDataSourceFactory.getPoolDataSource();
        poolDataSource.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource");
        poolDataSource.setURL(url);
        poolDataSource.setUser(user);
        poolDataSource.setPassword(password);
        poolDataSource.setInitialPoolSize(1);
        poolDataSource.setMinPoolSize(1);
        poolDataSource.setMaxPoolSize(10);
    }
    Connection connection = poolDataSource.getConnection();
    return connection;
}

I know that there is Connection.isValid() method to check whether a connection obtained from the pool is valid. But if isValid() returns false, what can I do? How do I force the connection pool to re-establish its connection?

Also, note that in our test environment, we are not using RAC (Real Application Clusters), but in production environment, we do have RAC. I have read that for RAC, we need to do some configuration in the codes in order for RAC to work.

Is it possible to have the same codes for RAC and non-RAC environments so that invalid connections in the pool re-established?

Thanks in advance.

1

1 Answers

0
votes

If your database is up and running then isValid() will return true indicating that app can connect to the DB. However, in the production system, there will be many nodes and if one of the nodes is down then UCP will get the connection from other nodes. Let me know if this clarifies your question.