Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is correct JDBC URL syntax if Oracle wallets are used?

Tags:

oracle

jdbc

There are 2 URL syntax, old syntax which will only work with SID and the new one with Oracle service name.
Old syntax

jdbc:oracle:thin:@[HOST][:PORT]:SID

New syntax

jdbc:oracle:thin:@//[HOST][:PORT]/SERVICE

What is correct JDBC URL syntax if Oracle wallets are used?
According to this article following URL syntax should be used:

jdbc:oracle:thin:/@db_alias  

But as I can see following URL works too:

jdbc:oracle:thin:@db_alias

Which of these syntaxes are correct?

like image 740
Volodymyr Bezuglyy Avatar asked Oct 03 '11 11:10

Volodymyr Bezuglyy


People also ask

What is the JDBC URL for Oracle?

Connection URL: The connection URL for the oracle10G database is jdbc:oracle:thin:@localhost:1521:xe where jdbc is the API, oracle is the database, thin is the driver, localhost is the server name on which oracle is running, we may also use IP address, 1521 is the port number and XE is the Oracle service name.

What is the JDBC driver for Oracle database?

Oracle Database 19c and 18c JDBC drivers introduce a new property file (ojdbc. properties) along with few other features that simplifies the connection to Autonomous Transaction Processing (ATP) and Autonomous Data Warehousing (ADW). Supports JDK8, JDK11, and JDK17 and implements JDBC 4.2 and JDBC 4.3 by ojdbc11.

Which Oracle JDBC driver should I use?

Which driver should I use? The best choice is to use Oracle JDBC thin driver. All the new enhancements and features are implemented only on JDBC Thin driver. If you are using a non-TCP/IP network you must use the OCI driver.


1 Answers

When you are using Oracle Wallet with a JDBC string, both syntax's are allowed, so long as your "db_alias" is setup in your Wallet store obviously.

Now, as far as using SQL*Plus with Oracle Wallet, the only format allowed with Oracle Wallet is:

/@db_alias

By the way, that article you referenced (and others) specifies you can only connect using JDBC if you use the OCI drivers, and not the thin client. This is/was typically because Java had no knowledge of the Oracle TNS and SQLNET files. This is in fact not true; you can connect using the JDBC thin driver with the latest Oracle Client & JDBC Drivers, but it just requires some setup. See http://tech.shopzilla.com/2011/09/oracle-wallet-with-thin-driver-with-connection-pool-with-database-timeouts/ for info on that, and below for a short summary.

Using Oracle Wallet with JDBC Thin Driver

  1. Configure Oracle Wallet as usual (which comes with the Oracle Database Client), creating the appropriate entries in your tnsnames.ora and sqlnet.ora files as well as the credential entry in your wallet
  2. Add the following JARs to your Java classpath. You should get these from the Oracle 11g client, and they can be found in the "jdbc" and/or "jlib" directories of where the client install is
    • Oracle JDBC Driver - ojdbc6.jar
    • Oracle Wallet - oraclepki.jar
    • Oracle Security Certs - osdt_cert.jar
    • Oracle Security Core - osdt_core.jar
  3. Start your Java application with the following system properties, pointing at your respective TNS and wallet directories:
    • -Doracle.net.tns_admin=C:\myTNSdir
    • -Doracle.net.wallet_location=C:\mywalletdir
  4. Then you can use a thin JDBC connection string in your application like so: jdbc:oracle:thin:/@MY_WALLET_DB_ENTRY
like image 84
David Hergert Avatar answered Sep 27 '22 18:09

David Hergert