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
CodePudding user response:
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