Troubleshooting
Problem
When you use the []oracle.jdbc.pool.OracleConnectionCacheManager[
] custom property with the Oracle.jdbc.pool.OracleDataSource data source, connections to an Oracle database might not be cached.
Cause
Custom properties on an Oracle data source are represented as a collection, which has no particular order. Therefore, it is not possible to configure data source properties in any order that guarantees that all of the connections are cached by the Oracle database.
Diagnosing The Problem
The following samples demonstrate instances in which caching does and does not occur.
In the following example, caching occurs:
import java.sql.Connection;
import java.sql.SQLException;
import oracle.jdbc.pool.OracleConnectionCacheManager;
import oracle.jdbc.pool.OracleDataSource;
public class OraceCachingBug {
static String url = null;
static OracleConnectionCacheManager occm = null;
public static void cacheCreatedSuccessfully()
throws Throwable
{
OracleDataSource ods = new OracleDataSource();
// The following property ordering results in
a cache being created.
ods.setConnectionCachingEnabled(true);
ods.setURL("jdbc:oracle:thin:@localhost:1521:IBM");
ods.setConnectionCacheName("ICC");
ods.setUser("scott");
ods.setPassword("manager1");
Connection conn = ods.getConnection("scott", "manager1");
System.out.println("before: " + occm.getNumberOfAvailableConnections("ICC") + "
connections are available in cache ICC");
conn.close();
System.out.println("after: " + occm.getNumberOfAvailableConnections("ICC") + "
connections are available in cache ICC");
System.out.println("success");
}
In the following example, caching does not occur:
public static void noCacheCreatedDueToOraBug()
throws Throwable
{
OracleDataSource ods = new OracleDataSource();
// The following property ordering causes no exception,
but no cache is created.
ods.setConnectionCacheName("ICC");
ods.setURL("jdbc:oracle:thin:@localhost:1521:IBM");
ods.setConnectionCachingEnabled(true);
ods.setUser("scott");
ods.setPassword("manager1");
Connection conn = ods.getConnection("scott", "manager1");
System.out.println("before: " + occm.getNumberOfAvailableConnections("ICC") + "
connections are available in cache ICC");
conn.close();
System.out.println("after: " + occm.getNumberOfAvailableConnections("ICC") + "
connections are available in cache ICC");
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);
}
System.out.println("test combination that causes cache
to be created");
cacheCreatedSuccessfully();
System.out.println("all done..");
}
}
Resolving The Problem
Contact Oracle support and reference the 6638862 fix.
Related Information
Was this topic helpful?
Document Information
Modified date:
06 June 2019
UID
swg21318192