The Java language, originally designed and promoted by Sun Microsystems and now
widely promoted by nearly everyone other than Microsoft, offers an extremely diverse
set of programming features, many of which are not available natively in PL/SQL. This
chapter introduces the topic of creating and using Java Stored Procedures in Oracle,
and shows how you can create and use JSP functionality from PL/SQL.
Oracle and Java
Starting with Oracle8i Database, the Oracle Database Server has included a Java Virtual
Machine that allows Java programs to run efficiently in the server memory space. Many
of the core Java class libraries are bundled with Oracle as well, resulting not only in a
formidable weapon in the programmer’s arsenal, but also a formidable topic for a
PL/SQL book! That’s why the objectives for this chapter are limited to the following:
• Providing the information you need to load Java classes into the Oracle database,
manage those new database objects, and publish them for use inside PL/SQL.
• Offering a basic tutorial on building Java classes that will provide enough guidance
to let you construct simple classes to access underlying Java functionality.
In preview, here is the usual way you will create and expose Java stored procedures:
1. Write the Java source code. You can use any convenient text editor or IDE such as
Oracle’s JDeveloper.
2. Compile your Java into classes and, optionally, bundle them into .jar files. Again,
you can use an IDE or Sun’s command-line javac compiler. (Strictly speaking, this
step is optional because you can load the source into Oracle and use the built-in
Java compiler.)
3. Load the Java classes into Oracle using the loadjava command-line utility or the
CREATE JAVA statement.
4. Publish the Java class methods by writing PL/SQL “wrappers” to invoke the Java
code.
5. Grant privileges as required on the PL/SQL wrapper.
6. Call the PL/SQL programs from any one of a number of environments, as illustrated
in Figure 27-1.
Figure 27-1. Accessing JSPs from within the Oracle database
Oracle offers a variety of components and commands to work with Java. Table 27-1
shows just a few of them.
Table 27-1. Oracle components and commands for Java
Component Description
“aurora” JVM The Java Virtual Machine (JVM) that Oracle implemented in its database server
loadjava An operating system command-line utility that loads your Java code elements (classes, .jar files, etc.) into the
Oracle database
dropjava An operating system command-line utility that drops your Java code elements (classes, .jar files, etc.) from the
Oracle database
CREATE JAVA DDL statements that perform some of the same tasks as loadjava and dropjava
DROP JAVA
ALTER JAVA
DBMS_JAVA A built-in package that offers a number of utilities to set options and other aspects of the JVM
The remainder of this chapter explains more about these steps and components. For
more coverage of Java in the Oracle database, you might also want to look at Java
Programming with Oracle JDBC by Donald Bales (O’Reilly). For more comprehensive
Java information, see the documentation from Sun Microsystems as well as the O’Reilly
Java series (as well as several other books I’ll recommend later in this chapter). For
more detailed documentation on using Oracle and Java together, see Oracle Corporation’s
manuals.
"News by powered"
No comments:
Post a Comment