Database Reference
In-Depth Information
password = password.trim();
host = host.trim();
port = port.trim();
String key = (instance + "/" + user).toUpperCase() ;
String connS = "jdbc:oracle:thin:" + user + "/" + password + "@" +
host + ":" + port + ":" + instance;
boolean testSuccess = true ;
if( testFirst ) {
Connection mConn = null;
try {
mConn = DriverManager.getConnection( connS );
Statement stmt = mConn.createStatement();
ResultSet rs = stmt.executeQuery(
"SELECT SYSDATE FROM DUAL" );
System.out.println( "Connection string successful" );
} catch( Exception x ) {
System.out.println( "Connection string failed!" );
testSuccess = false ;
} finally {
try {
if( null != mConn ) mConn.close();
} catch( Exception x ) {}
}
}
if( testSuccess ) {
try {
appAuthCipherDES.init( Cipher. ENCRYPT_MODE ,
appAuthSessionSecretDESKey, appAuthParamSpec );
byte[] bA = appAuthCipherDES.doFinal( connS.getBytes() );
connsHash.put(key, new RAW( bA ) ) ;
} catch( Exception x ) {}
}
}
Finally, if we've decided we like the connection string ( testSuccess is true ), we add it to connsHash .
And, like the connection strings we (perhaps) received from Oracle, we store it here in encrypted form,
based on the shared password key we got from Oracle database.
The HashMap , connsHash , is keyed on the string “INSTANCE/USER” that we assembled from the
instance name and user name that were provided to us. If we are calling this method with the same
instance and user as an existing entry in connsHash , the new connection string will overwrite the old
(assuming it's acceptable).
Client Call to Store List of Connection Strings on Oracle
Once we've filled out the ranks of one or more connection strings that we want to use with our
application, we can call the putAppConnections() method to submit the connsHash to Oracle Database.
We see this method in Listing 10-24.
Note again that we need to have already exchanged keys with Oracle database. Assuredly we have,
else we wouldn't have been able to get the previously existing connsHash from Oracle, nor would we have
been able to add new connection strings to connsHash —we would have nothing to submit.
 
Search WWH ::




Custom Search