When True Cache is configured, applications must decide whether to query data from True Cache or the primary database. There are two ways to do this:

The JDBC method does the following:

  1. The client application creates a logical connection to connect to the primary database application service called SALES by using the connection's useTrueCacheDriverConnection parameter.
  2. The application flags the logical connection as setReadOnly(true) or setReadOnly(false) to direct SQL statements to True Cache or the primary database, respectively. For each logical connection, the JDBC Thin driver internally maintains two physical connections: one to the primary database and one to True Cache. Both connections were associated when the database application service SALES was created.

The JDBC method is illustrated in the following code:

static String url_primary = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=?(ADDRESS=(PROTOCOL=tcp)(HOST=primary_host)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=sales)(SERVER=DEDICATED)))";

OracleDataSource ods1 = new oracle.jdbc.pool.OracleDataSource();

ods1.setURL(url_primary);
ods1.setUser(user);
ods1.setPassword(password);

ods1.setConnectionProperty("oracle.jdbc.useTrueCacheDriverConnection","true");

Connection conn1 = ods1.getConnection();

verifyConnection(conn1); // This is connected to primary

conn1.setReadOnly(true)

verifyConnection(conn1); // This is connected to True Cache

conn1.setReadOnly(false)

verifyConnection(conn1); // This is connected back to primary