1

I am trying to connect to an RAC database through JDBC with the connection string in properties file.

Here is the properties file.

datasource-url=jdbc\:oracle\:thin\:@(DESCRIPTION=(ADDRESS_LIST=(LOAD_BALANCE=ON)(FAILOVER=ON)(ADDRESS=(PROTOCOL=TCP)(HOST=171.17.aa.ee)(PORT=21521))(ADDRESS=(PROTOCOL=TCP)(HOST=171.17.aa.dd)(PORT=21521))(ADDRESS=(PROTOCOL=TCP)(HOST=171.17.aa.cc)(PORT=21521))(ADDRESS=(PROTOCOL=TCP)(HOST=171.17.aa.bb)(PORT=21521)))(CONNECT_DATA=SERVICE_NAME=ssss)(SERVER=DEDICATED)))
datasource-username=xxxx
datasource-password=yyyy
driver-class=oracle.jdbc.driver.OracleDriver

I am reading this properties file from java code where I create a connection. Unfortunately, I am getting these two exceptions.

SQLException-Invalid connection string format, a valid format is: "host:port:sid"
SQLException-NL Exception 

What is wrong here? Thanks in advance.

EDIT 1: I was using odbc14.jar , So I thought of using some other jar. I used odbc7.jar and these 2 exceptions vanished but got a new exception-- SO Exception was generated.

My jdk version is 1.7

Jaydeep
  • 149
  • 2
  • 5
  • 19

2 Answers2

0

You can use either:

  • scan listener DNS name: (scan hostname uses DNS loadbalancing, so you get multiple A records for one hostname)

    url=jdbc:oracle:thin:@//scan-hostname:port/servicename

  • Another option is to use tnsnames.ora file. As described here. Then you can let DBAs to maintain this a let them make changes in this file.

  • 3rd option is to play with quotes and backslashes, till it starts working. I think this jdbc\oracle should be rewritten as jdbc:oracle or jdbc\:oracle.

Community
  • 1
  • 1
ibre5041
  • 4,903
  • 1
  • 20
  • 35
0

Finally, got it working. Posting the properties for others to refer. I used odbc7.jar .

datasource-url=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=171.17.aa.bb)(PORT=21521))(ADDRESS=(PROTOCOL=TCP)(HOST=171.17.aa.cc)(PORT=21521))(ADDRESS=(PROTOCOL=TCP)(HOST=171.17.aa.dd)(PORT=21521))(ADDRESS=(PROTOCOL=TCP)(HOST=171.17.aa.ee)(PORT=21521)))(LOAD_BALANCE=yes)(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=zzzz)))
datasource-username=xxx
datasource-password=yyy
driver-class=oracle.jdbc.OracleDriver

i.e changed url and driver class. Hope this helps.

Jaydeep
  • 149
  • 2
  • 5
  • 19
  • 1
    If you are using Java7 you should not use the outdated `odbc14.jar` (which is intended for Java **1.4**) but `ojdbc7.jar` instead. Also: your driver versions seems to be for Oracle 10. Are you really such an outdated version? –  Oct 22 '15 at 10:32
  • I tried to use odbc7.jar but it gave SO exception that I found means java and jdbc versions are compitable. So, tried changing it and it worked. Will try again with odbc7.jar and will post the result. – Jaydeep Oct 22 '15 at 10:39
  • Got it working with odbc7.jar too. So only changes were url and driver class – Jaydeep Oct 26 '15 at 05:51