Thursday, March 26, 2015

JDBC URL to connect RAC database or How add multiple hosts in jdbc url

Today I will share new problem which I have solved.

In my last project I was connected to Oracle database (RAC) database using multiple hosts and I want to share oracle connection string which uses multiple hosts.

So while you are connecting from oracle clients (as PL/SQL developer) it is easy to define multiple hosts in tnsnames.ora

dbnameTest = 
  (ADDRESS = (PROTOCOL = TCP)(HOST = = 1521))
  (ADDRESS = (PROTOCOL = TCP)(HOST = = 1521))
  (LOAD_BALANCE = yes)
    (SERVICE_NAME = testDB)
But how we can define our connection string in Java to connect such database (which uses multiple hosts)?
It is easy - just copy the tnsentries from your tnsnames.ora to connection string as below

If you want to connect multiple hosts from mysql u can use below connection string:

That is all :)

No comments:

Post a Comment