Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Programming PL SQL.doc
Скачиваний:
3
Добавлен:
01.07.2025
Размер:
5.06 Mб
Скачать

Chapter 22. Calling Java from pl/sql

In this chapter, I explore an exciting feature introduced in Oracle8i that allows a developer to call Java stored procedures ( JSPs) from within PL/SQL. Java is a very powerful language, more robust in many ways than PL/SQL. Java also offers hundreds of classes that provide clean, easy-to-use Application Programming Interfaces (APIs) to a wide variety of functionality.

22.1 Oracle and Java

Beginning with the Oracle8i release, Oracle includes a product called JServer, which consists of the following elements:

  • Oracle's Java Virtual Machine ( JVM), called Aurora; the supporting runtime environment; and Javaclass libraries

  • Tight integration with PL/SQL and Oracle RDBMS functionality

  • An Object Request Broker (the Aurora/ORB) and Enterprise JavaBeans (EJB)

  • The JServer Accelerator (native compiler)

The Aurora JVM executes Javamethods (also known as Java stored procedures, or JSPs) and classes if they were stored in the database itself.

Java in the Oracle database is a big topic; Java programming all by itself is an even bigger topic. Complete treatment of either is outside the scope of this book. My 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 in building Java classes that will provide enough guidance to let you construct simple classes to access underlying Java functionality

To access Java class methods from within Oracle, you must take the following steps:

  1. Create the Java code elements. You can do this inOracle's JDeveloper or in any other Java Integrated Development Environment. (In a pinch, notepad.exe will also do the trick!)

  2. Load the Java classes into Oracle using the loadjava command-line utility or the CREATE JAVA statement.

  3. Publish the Java class methods inside PL/SQL by writing wrapper programs in PL/SQL around the Java code.

  4. Grant privileges as required on the PL/SQL wrapper programs and the Java class referenced by the PL/SQL wrapper.

  5. Call the PL/SQL programs from any one of a number of environments, as illustrated in Figure 22-1.

Figure 22-1. Accessing jsPs from within the Oracle database

Oracle offers a variety of components and commands to work with Java. Table 22-1 summarizes these different elements.

Table 22-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 JAVADROP JAVAALTER JAVA

New DDL statements that perform some of the same tasks as loadjava and dropjava

DBMS_JAVA

A built-in package that offers a number of utilities to set options and other aspects of the JVM

JPublisher

A utility used to build Java classes around object types and REFs defined in the Oracle database

The remainder of this chapter explains these steps and components. For more thorough coverage of Java in the Oracle database, consult the Oracle documentation. You might also want to look at Java Programming with Oracle JDBC by Donald Bales, and Java Programming with Oracle SQLJ by Jason Price, both from O'Reilly.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]