Database Reference
In-Depth Information
C H A P T E R 4

Java Stored Procedures
When I first discovered Java stored procedures, I made a formal presentation of my findings to the IT
department of the company where I worked, giving several examples, including using Java in an Oracle
database to send e-mail, to read web pages, and to calculate Unix crypt values for the authentication of
application users. That was in 2001, and as we shall see as we go through this text, I am still presenting
the same ideas. However, it is only now that these ideas can be realized, on account of the upgrade to the
Oracle JVM that happened with Oracle database 11g. With Oracle database 11g, Oracle has upgraded the
Oracle JVM to run with Java version 1.5, which includes a significant upgrade to the Java cryptography
extension (JCE) package included with the JVM.
So, what does Java encryption have to do with Oracle? Well, the standard Oracle database does not
provide encryption of data for transmission to client applications out of the box. You can buy add-ons,
such as Oracle Advanced Security, to provide it, but with the Oracle JVM running in the database, we can
use Java to do data encryption on the Oracle database. The only way to get to that Java functionality in
Oracle database is through Java stored procedures. Having the power of programs written in Java
running in the Oracle database will give us encryption and much more.
There was no impediment to running enhanced encryption in previous versions of the Oracle JVM,
and I have been doing so ever since my initial presentation in 2001. The only problem was one of effort
and standardization, and the vetting (acceptance) of the algorithms. Before enhancements to JCE in Java
1.5, we had to acquire algorithms or write them ourselves and manually install them in Oracle database.
However, for encryption, we are now able to call on the standard functions and algorithms included in
JCE.
In this chapter, we will learn how to connect from SQL queries on the Oracle database to the Oracle
JVM in order to let Java do our processing and return data to us. We will also cover the basics of
connecting to Oracle database from Java and running database queries. In fact, we will connect from
Oracle through Java, using Java to read Oracle.
Java Stored Procedure Example
Nothing speaks to a programmer more clearly than code. Let the example that I'm going to present serve
as a guide to begin understanding how Java stored procedures work. You will see an Oracle header to the
Java code shown in Listing 4-1 in bold font. And you will also observe the definition of an Oracle
function, following the Java code, which encapsulates the Java code. You cannot call Java code directly
from an Oracle query, but you can call the Oracle function or procedure which will then call and run the
Java.
Place a bookmark here so you can refer back Listing 4-1 in the discussion that follows. We will load
this code into the Oracle database shortly.
 
Search WWH ::




Custom Search