Connecting to Oracle Real Application Clusters (RAC) with JDBC
Connecting to an Oracle RAC system is similar to connecting to a single instance of an Oracle database. When connecting to a single Oracle database instance, you specify the SID or ServiceName of the instance to which you want to connect either in the connection URL or as properties of a DataSource. For example, the following URL establishes a connection to the database instance Accting1:
jdbc:datadirect:oracle://server1:1521;ServiceName=Accting1
In a RAC environment, multiple Oracle instances share the same physical data. In addition to the SID or ServiceName for each Oracle instance in the Oracle RAC system, a ServiceName exists for the entire Oracle RAC system. When an application uses the Oracle RAC system's ServiceName, the Oracle RAC system appears to be a single Oracle instance to the application. For example, the following URL establishes a connection to an Oracle instance in the Oracle RAC system named Accounting:
jdbc:datadirect:oracle://server1:1521:ServiceName=Accounting
The specific instance that is connected to is determined by a number of factors, including which instances are available and the load on those instances. Typically, the application does not need to know which instance to which it is connected.
Retrieving Connection Information from a tnsnames.ora File
DataDirect Connect for JDBC Oracle driver also supports retrieving specific connection information, including connection failover and client load balancing instructions, from a tnsnames.ora file. The type of information the DataDirect Connect for JDBC Oracle driver allows you to retrieve from a tnsnames.ora file includes:
- Oracle server name and port
- Oracle System Identifier (SID) or Oracle service name
- Server process type (shared or dedicated)
- Connection failover and client load balancing instructions
tnsnames.ora File Example
In a tnsnames.ora file, connection information for Oracle services is associated with a net service name. The following example shows connection information in a tnsnames.ora file configured for an Oracle RAC system identified by the net service name entry, ARMSTRONG.ACCT.
ARMSTRONG.ACCT =
(DESCRIPTION =
(ADDRESS_LIST=
(ADDRESS= (PROTOCOL = TCP)(HOST = server1)(PORT = 1521))
(ADDRESS= (PROTOCOL = TCP)(HOST = server2)(PORT = 1521))
(ADDRESS= (PROTOCOL = TCP)(HOST = server3)(PORT = 1521))
(FAILOVER = on)
(LOAD_BALANCE = on)
)
(CONNECT_DATA=
(SERVICE_NAME = acct.us.yourcompany.com)
)
)
If the DataDirect Connect for JDBC Oracle driver referenced the network service name entry ARMSTRONG.ACCT as shown in this example, the driver would connect to the Oracle RAC system identified by the net service name acct.us.yourcompany.com
(SERVICE_NAME=acct.us.yourcompany.com). In addition, the driver would enable connection failover (FAILOVER=on) and client load balancing (LOAD_BALANCE=on) for all connections to that system.
Alternatively, DataDirect Connect for JDBC provides a way to enable connection failover and client load balancing through driver properties specified in a connection URL or data source. For example, the following connection URL enables both of these features:
jdbc:datadirect:oracle//server1:1521;AlternateServers= (server2:1521,server3:1521,server4:1521);LoadBalancing=true




