I have a Java application that uses JDBC (via JPA) that was connecting to a development database using hostname, port and Oracle SID, like this:
jdbc:oracle:thin:@oracle.hostserver1.mydomain.ca:1521:XYZ
XYZ was the Oracle SID. Now I need to connect to a different Oracle database that does not use a SID, but uses an Oracle "Service Name" instead.
I tried this but it doesn't work:
jdbc:oracle:thin:@oracle.hostserver2.mydomain.ca:1522:ABCD
ABCD is the Service Name of the other database.
What am I doing wrong?
http://download.oracle.com/docs/cd/B28359_01/java.111/b31224/urls.htm#BEIDHCBA
So I would try:
jdbc:oracle:thin:@//oracle.hostserver2.mydomain.ca:1522/ABCD
Also, per Robert Greathouse's answer, you can also specify the TNS name in the JDBC URL as below:
Try this:
jdbc:oracle:thin:@oracle.hostserver2.mydomain.ca:1522/ABCD
Edit: per comment below this is actualy correct:
jdbc:oracle:thin:@//oracle.hostserver2.mydomain.ca:1522/ABCD
(note the//
)Here is a link to a helpful article
So there are two easy ways to make this work. The solution posted by Bert F works fine if you don't need to supply any other special Oracle-specific connection properties. The format for that is:
However, if you need to supply other Oracle-specific connection properties then you need to use the long TNSNAMES style. I had to do this recently to enable Oracle shared connections (where the server does its own connection pooling). The TNS format is:
If you're familiar with the Oracle TNSNAMES file format, then this should look familiar to you. If not then just Google it for the details.
This discussion helped me resolve the issue I was struggling with for days. I looked around all over the internet until I found the answered by Jim Tough on May 18 '11 at 15:17. With that answer I was able to connect. Now I want to give back and help others with a complete example. Here goes:
When using
dag
instead ofthin
, the syntax below pointing to service name worked for me. Thejdbc:thin
solutions above did not work.You can also specify the TNS name in the JDBC URL as below