1

Based on oracle document, I create a wallet

mkstore -wrl /tmp/wl -create

Add a credential

mkstore -wrl /tmp/wl -createCredential localhost:1521/myservice user pass

In my java application, I want to connect to the database via this wallet

public static void main(String... args) throws Exception { 
  Class.forName("oracle.jdbc.driver.OracleDriver"); 
  System.setProperty("oracle.net.wallet_location", "/tmp/wl");
  Connection connection = DriverManager.getConnection("WHAT TO PUT HERE?");
}

But I don't know how to fill the connection string. I would like NOT to use tnsnames.ora Thanks

SoT
  • 898
  • 1
  • 15
  • 36

2 Answers2

1

In my experience, use of tnsnames.ora was required when using a wallet for authentication, even for JDBC Thin connections. The connection alias in tnsnames.ora is matched to the connection alias in the wallet to provide the correct credential for a given connection.

That said, the latest documentation seems to say that you can enter a connection string along the lines of myhost:1521/myservice or (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=myhost-scan)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=myservice))) as the db_connect_string parameter in the wallet. This would presumably negate the need for tnsnames.ora, as long as your connection URL after the "@" matched the db_connect_string in the wallet.

You connection URL then looks something like this:

jdbc:oracle:thin:@myhost:1521/myservice
pmdba
  • 6,457
  • 2
  • 6
  • 16
  • Thank you @pmdba, i have a question, if tnsnames.ora is required, why they allow us to set the connection string into the wallet? Wwhat is the use of the connection string? – SoT Mar 24 '22 at 16:55
  • Like this: mkstore -wrl /tmp/wl -createCredential localhost:1521/myservice user pass – SoT Mar 24 '22 at 16:55
  • Good point: i'm revising my answer – pmdba Mar 24 '22 at 17:10
  • Thank you so much. Now i can make it work – SoT Mar 24 '22 at 17:23
1

You can pass wallet related connection properties as part of the connection URL. You can skip using tnsnames.ora. See JDBC developer's guide for some examples.

Nirmala
  • 1,278
  • 1
  • 10
  • 11