2

I am trying to connect oracle with jdbc using the following url

String url = "jdbc:oracle:thin:@<host>:1522:dev;includeSynonyms=true";

But it is throwing the following error.

java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
<host>:1522:dev;includeSynonyms=true

If I am removing the property(includeSynonyms=true) from the url, I am able to connect.

I am using ojdbc14.jar

please help me

Nandkumar Tekale
  • 16,024
  • 8
  • 58
  • 85
Sreekanth P
  • 1,187
  • 2
  • 12
  • 16
  • 1
    Unrelated to your problem: are you really still using Java **1.4** (because that's what the driver is for). –  Jan 22 '13 at 11:06

3 Answers3

3

You can't (AFAIK) set this as part of the URL. As per the OracleDriver documentaion:

Specifying a Database URL and Properties Object

The following signature takes a URL, together with a properties object that specifies user name and password (perhaps among other things):

getConnection(String URL, Properties info);

Where the URL is of the form:

jdbc:oracle:<drivertype>:@<database>

In addition to the URL, use an object of the standard Java Properties class as input. For example:

java.util.Properties info = new java.util.Properties();
info.put ("user", "scott");
info.put ("password","tiger");
info.put ("defaultRowPrefetch","15");
getConnection ("jdbc:oracle:oci8:@",info);

The table that lists the connection properties that Oracle JDBC drivers support includes includeSynonyms, so you should be able to do:

String url = "jdbc:oracle:thin:@//<HOST>:1522/dev"
java.util.Properties info = new java.util.Properties();
info.put ("includeSynonyms", "true");
getConnection (url, info);

Untested I'm afraid, and I'm not sure if it works with your driver version. You could also look at setting it later via an OracleConnection or OracleConnectionWrapper.

Also not entirely sure that URL form works with the 1.4 driver, though I think it does - you might need to use your original @<host>:1522:dev form. And note that in the easy connect format, dev refers to the service name rather than the SID, and they might not be the same; check what lsnrctl status shows if this is problematic.

Alex Poole
  • 183,384
  • 11
  • 179
  • 318
0

Do you use URL from url variable without changing <host> into IP address? If so, then simply change it to address of Oracle server.

You should also read about connecting tp Oracle via JDBC: http://docs.oracle.com/cd/B10501_01/java.920/a96654/basic.htm There is even info about setting connection properties including includeSynonyms.

Michał Niklas
  • 53,067
  • 18
  • 70
  • 114
  • You wouldn't get the ORA-12505 if it wasn't connecting to the listener, so the host must just be obscured in the question. The message suggests it's trying to interpret the entire `dev;includeSynonyms=true` portion as a SID. – Alex Poole Jan 22 '13 at 11:09
  • So it seems that your diagnose with separate property setting is correct. – Michał Niklas Jan 22 '13 at 11:22
-1

you need to add a TNS name after the @ symblol ie if the oracle db tns name is dev it would translate to:

String url = "jdbc:oracle:thin:@//<HOST_IP>:1522:dev;includeSynonyms=true";

use a forward slash instead of a full colon

korefn
  • 955
  • 6
  • 17
  • 1
    thanks for the reply. I tried with that now it is throwing java.sql.SQLException: Io exception: NL Exception was generated – Sreekanth P Jan 22 '13 at 10:14
  • AFAIK `NL Exception` in this case means that your JDBC url contains a syntax error. – Mark Rotteveel Jan 22 '13 at 10:37
  • I've seen the problem and edited appropriately. Are you using the forward slashes before the host ip? Also ensure the name `dev` is the TNS name of the database you wish to connect to. – korefn Jan 22 '13 at 11:17