Oracle Connection Caching Problem With Datasource Property Order (Doc ID 565732.1)

Last updated on AUGUST 28, 2017

Applies to:

JDBC - Version 10.2.0.4 to 11.1.0.6 [Release 10.2 to 11.1]
Information in this document applies to any platform.
This problem can occur on any platform.

Symptoms

Oracle connection caching gets enabled only if DataSource custom properties are put in certain
order. When enabling connection cache with following code, the connection cache is created but not with the properties that have been specified:

ds.setFastConnectionFailoverEnabled(true);
ds.setONSConfiguration("nodes=A1:6200, A2:6200");
ods.setConnectionCacheName("ICC");
ods.setURL("jdbc:oracle:thin:@localhost:1521:orcl");
ods.setConnectionCachingEnabled(true);


Any subsequent calls to <ODS>.getConnectionCacheName() returns NULL and not the expected name "ICC".

<ODS>.setConnectionCacheName has no effect prior to .setConnectionCachingEnabled. This also shows that connection caching is enabled, but that the name is set to a default value and has to be retrieved.

The following is an example that shows the behavior:

import java.sql.Connection;
import java.sql.SQLException;
 
import oracle.jdbc.pool.OracleConnectionCacheManager;
import oracle.jdbc.pool.OracleDataSource;
 
public class OracleCachingBug
{
   static String url = "jdbc:oracle:thin:@localhost:1521:orcl";
  static OracleConnectionCacheManager occm = null;
 
  public static void cacheCreatedSuccessfully()
    throws Throwable
  {
    OracleDataSource ods = new OracleDataSource();
 
    //  following causes no exception, but no cache is created.
    ods.setConnectionCachingEnabled(true);
    ods.setURL(url);
    ods.setConnectionCacheName("ICC");
 
    ods.setUser("SCOTT");
    ods.setPassword("TIGER");
 
    Connection conn = ods.getConnection("SCOTT", "TIGER");
 
    String cacheName = ods.getConnectionCacheName();

    System.out.println("Getting Available Connections on "+cacheName);
    System.out.println("before: " +
                       occm.getNumberOfAvailableConnections(cacheName) +
//                       occm.getNumberOfAvailableConnections("ICC") + 
                       " connections are available in cache "+cacheName);
    conn.close();
    System.out.println("after: " +
                       occm.getNumberOfAvailableConnections(cacheName) +
                       " connections are available in cache "+cacheName);

    System.out.println("success");
  }
 
  public static void noCacheCreatedDueToOraBug() throws Throwable
  {
    OracleDataSource ods = new OracleDataSource();
 
    //  following causes no exception, but no cache is created.
    ods.setConnectionCacheName("ICC");
    ods.setURL(url);
    ods.setConnectionCachingEnabled(true);
    ods.setUser("SCOTT");
    ods.setPassword("TIGER");
 
    Connection conn = ods.getConnection("SCOTT", "TIGER");
 
    String cacheName = ods.getConnectionCacheName();

    System.out.println("Getting Available Connections on "+cacheName);
    System.out.println("before: " + 
                       occm.getNumberOfAvailableConnections(cacheName) + 
//                       occm.getNumberOfAvailableConnections("ICC") + 
                       " connections are available in cache "+cacheName);
    conn.close();
    System.out.println("after: " + 
                       occm.getNumberOfAvailableConnections(cacheName) + 
                       " connections are available in cache "+cacheName);
 
    System.out.println("success");
  } 
 
  public static void main(String[] args) throws Throwable
  {
    occm = 
        OracleConnectionCacheManager.getConnectionCacheManagerInstance();   
   
    System.out.println("test combination that causes cache to NOT get created");
 
    try
    {
      noCacheCreatedDueToOraBug();
    }
    catch (SQLException x)
    {
      System.out.println("test failed, exception is: " + x);
      x.printStackTrace();
    }
 
    System.out.println("test combination that causes cache to be created");
    cacheCreatedSuccessfully();
 
    System.out.println("all done..");
  }
}



Output:-

test combination that causes cache to NOT get created
Getting Available Connections on OracleDataSource#0x0
before: 0 connections are available in cache OracleDataSource#0x0
after: 1 connections are available in cache OracleDataSource#0x0
success

test combination that causes cache to be created
Getting Available Connections on ICC
before: 0 connections are available in cache ICC
after: 1 connections are available in cache ICC
success
all done..

Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms