How can I use the connection string along with jdbc url

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

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

But this causes 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 remove the property (includeSynonyms = true) from the url, I can connect.

I am using ojdbc14.jar

Please help me

+2
source share
3 answers

You cannot (AFAIK) set this as part of a URL. According to OracleDriver documentation :

Specifying the database URL and property object

The following signature accepts a URL along with a property object that indicates a username and password (possibly, by the way):

 getConnection(String URL, Properties info); 

If the URL is of the form:

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

In addition to the URL, use the standard Java properties object class as an input. For instance:

 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 listing the connection properties supported by Oracle JDBC drivers includes includeSynonyms , so you should be able to:

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

Faulty, I'm afraid, and I'm not sure if it works with your version of the driver. You can also see how to install it later through OracleConnection or OracleConnectionWrapper .

Also, I’m not entirely sure that the URL form works with the 1.4 driver, although I think that it is so - you may need to use the original @<host>:1522:dev form. Note that in easy connect, the dev format refers to the service name, not the SID, and they may not be the same; check what lsnrctl status shows if this is problematic.

+3
source

Are you using the URL from the url variable without changing the <host> to the IP address? If so, just change it to the address of the 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 information about setting connection properties, including includeSynonyms .

0
source

you need to add the TNS name after the @ character, i.e. if the name oracle db tns is dev, it will translate to:

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

use a slash instead of a full colon

-1
source

All Articles