Everyone knows how you connect to a single Oracle Database using JDBC:
jdbc:oracle:thin:@TS-ORA10:1521:UNICODE
But what if you want to test a failover scenario to loop through multiple nodes running Oracle RAC?
Here is one solution (assuming a 2-Node Oracle RAC cluster):
<connection-url>jdbc:oracle:thin:@
(DESCRIPTION =
(LOAD_BALANCE = yes)
(ADDRESS = (PROTOCOL = TCP) (HOST = host1-vip)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP) (HOST = host2-vip)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = db-service)
(FAILOVER_MODE = (TYPE = SELECT) (METHOD = BASIC)(RETRIES = 180)(DELAY = 5))
)
)</connection-url>
Where:
[ul]
[li]host1-vip = virtual IP of node1
[/li][li]host2-vip = virtual IP of node2
[/li][li]db_service = the Service name of the database
[/li][/ul]
So for instance:
[ul]
[li]host1-vip = MISCDATA1V.DB.PERCU.COM
[/li][li]host2-vip = MISCDATA2V.DB.PERCU.COM
[/li][li]db_service = PMISC.db.percu.com
[/li][/ul]
<connection-url>jdbc:oracle:thin:@
(DESCRIPTION =
(LOAD_BALANCE = yes)
(ADDRESS = (PROTOCOL = TCP) (HOST = MISCDATA1V.DB.PERCU.COM) (PORT = 1521))
(ADDRESS = (PROTOCOL = TCP) (HOST = MISCDATA2V.DB.PERCU.COM) (PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = PMISC.db.percu.com)
(FAILOVER_MODE = (TYPE = SELECT) (METHOD = BASIC)(RETRIES = 180)(DELAY = 5))
)
)</connection-url>