The first task is to create a wallet. Below, I created two sets of credentials for the same user; RIAD_JAVA. I created two because I wanted to try two types of configurations. One which uses the database connection string and the other which uses a TNS alias.
#first create the wallet
mkstore -wrl t-riad-wallet -create
#create first of two credentials for user RIAD_JAVA. This will be used for configuration, which needs a tnsname.ora file.
mkstore -wrl t-riad-wallet -createCredential triad RIAD_JAVA secret2015$
#create second set of credentials also for RIAD_JAVA but this time with part of the connection string taken for the java programms externalized properties file. The configuration won't need a tnsname.ora file.
mkstore -wrl t-riad-wallet -createCredential
t-riad-dwh-db.tadnet.net:1521/triad.tst.tadnet.net RIAD_JAVA secret2015$
Before continuing, let me give an over view of what will be shown.
1. Configuration Using thin client (jdbc:oracle:thin:)
a.) with Database Configuration String (@hostname:port:service)b.) with TNS alias (@anyalias which can be found in tnsname.ora)
2. Configuration Using oci (jdbc:oracle:oci:)
1. Configuration Using thin client (jdbc:oracle:thin:)
The following jars are needed:
ojdbc6-11.3.0.jar, oraclepki.jar and ucp.jar
a.) with Database Configuration String
Set up the Java application with the following connection string. This should correspond to what was used while creating the second set of credentials above.
Program must be started with the following JVM parameter:
oracle.net.wallet_location
Example:
java -cp
.:/global/riad-app/tomcat/lib/ojdbc6-11.3.0.jar:./jlib/oraclepki.jar:./ucp.jar
-Doracle.net.wallet_location=/tmp/wallet/t-riad-wallet WalletTest
Note: no tnsname.ora file is needed only the a copy of the wallet created above.
b.) with TNS alias
The above mentioned jar will also be need here. This time the connection string is as follows, which is what was used to create the first set of credentials above.
Program must be started with the following JVM parameters:
oracle.net.wallet_location
oracle.net.tns_admin
The following tnsnames.ora will be needed and should exist where oracle.net.wallet_location shown above points to.
triad =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(Host = t-riad-dwh-db.tadnet.net)(Port = 1521))
)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = triad.tst.tadnet.net)
)
)
Example call:
java -cp
.:./ojdbc6-11.3.0.jar:./jlib/oraclepki.jar:./ucp.jar -Doracle.net.wallet_location=/tmp/wallet/t-riad-wallet -Doracle.net.tns_admin=/tmp/wallet WalletTest
2. Configuration Using oci (jdbc:oracle:oci:)
Here the jdbc connection string looks as follows:jdbc:oracle:oci:/@triad
Before starting the programm the following enviroment variables are needed:
ORACLE_HOME=/opt/oracle/product/11.2.0;export
ORACLE_HOME
LD_LIBRARY_PATH=/opt/oracle/product/11.2.0/lib:$LD_LIBRARY_PATH;
export LD_LIBRARY_PATH
Also a tnsname.ora file
and a sqlnet.ora file are need.