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.