Database Reference
In-Depth Information
Listing 5-17. Handling Errors from a Stored Procedure
int errNo = stmt.getInt( 4 );
if( errNo != 0 ) {
String errMsg = stmt.getString( 5 );
System.out.println( "Oracle error " + errNo + ", " + errMsg );
System.out.println( (stmt.getRAW( 3 )).toString() );
}
Notice how we also print out the data that is returning to us in the RAW parameter, number 3.
Normally that would hold the encrypted data ( SYSDATE ) from the p_get_rsa_crypt_sysdate procedure;
but when there's an error, it will hold the name of the Java method, running in the Oracle JVM, where the
error occurred. This information is difficult to gather unless you go to these efforts, or log the errors in
the Oracle JVM and read through the logs. We will do both.
Decrypting at the Client
Normally, when there is no error, we read our non-error-related OUT parameter, number 3, the RAW
element that is our encrypted data. Here we read it and assign the value to the cryptData RAW . Then we
call the getRSADecryptData() method to decrypt it. And finally, we print out the data, which is the server
timestamp. These actions are shown in Listing 5-18.
Listing 5-18. Decrypting the Data from the Stored Procedure
else {
RAW cryptData = stmt.getRAW( 3 );
newSampleData = getRSADecryptData( cryptData );
System.out.println( "Server date: " + newSampleData );
}
Running Our Code Again
If you have any troubles completing this, refer to the previous section in this chapter, “Running Our
Code.” You will have to have loaded the Java code on the Oracle Database as described in the section
“Load OracleJavaSecure Java into Oracle Database.”
You will change directories to Chapter5 and compile the code with the following command. As a
reminder, you will need to have ojdbc.jar in your CLASSPATH .
javac orajavsec/OracleJavaSecure.java
Then run the code from that same directory with this command:
java orajavsec.OracleJavaSecure
Observing the Results
With the edits you made in the second half of this chapter to OracleJavaSecure.java , the main() method
will continue to run the client/server tests. The first line shown below is printed from the
encryption/decryption methods running on the client only; and the second line comes from the
client/server encryption/decryption process:
Client date: Sat Dec 04 14:59:49 EST 2010
 
Search WWH ::




Custom Search