Listing 1
// Example to show binding of OracleDataSource to JNDI
// with relevant cache properties set on the datasource.
import oracle.jdbc.pool.*; // import the pool package
Context ctx = new IntialContext(ht);
OracleDataSource ods = new OracleDataSource();
// Set Datasource properties
ods.setUser("Scott");
ods.setPassword("tiger");
ods.setConnectionCachingEnabled(True);
ods.setConnectionCacheName("MyCache");
ods.setConnectionCacheProperties(cp);
ods.setURL("jdbc:oracle:thin:@(DESCRIPTION= (LOAD_BALANCE=on)
(CONNECT_DATA=(SERVICE_NAME=service_name)))");
// Enable fast connection failover
ods.setFastConnectionFailoverEnabled(true);
ctx.bind("MyDS", ods);
...
ds = lookup("MyDS"); // lookup datasource from the cache
// implicitly create connection cache, that is set up for fast
// connection failover
conn = ds.getConnection();
...
// return connection to the cache
conn.close();
...
// close datasource and cleanup the cache
ods.close()
Listing 2
java.util.properties cacheProps = new Properties();
java.util.properties cacheWeights = null;
cacheWeights.setProperty("NLSLANG", "10");
cacheWeights.setProperty("SecurityGroup", "8");
cacheWeights.setProperty("Application", "4");
...
// set weights on the cache
cacheProps.put(CacheAttributeWeights, cacheWeights);
...
Listing 3
java.util.properties connAttr = null;
connAttr.setProperty("NLSLANG", "ISO-LATIN-1");
connAttr.setProperty("SecurityGroup", "1");
connAttr.setProperty("Application", "HR")
// Request connection
ds.setCacheName("MyCache");
// First retrieval of connection from myCache
conn = ds.getConnection(connAttr);
...
// apply attributes on the connection
conn.close(connAttr);
...
// Next retrieval finds the connection in the cache
conn = ds.getConnection(connAttr);