Reputation: 1227
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
Upvotes: 2
Views: 6251
Reputation: 955
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
Upvotes: -1
Reputation: 191235
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.
Upvotes: 3
Reputation: 54292
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
.
Upvotes: 0