Oracle PL/SQL Programming Guide to Oracle 8i Features

Oracle PL/SQL Programming Guide to Oracle 8i FeaturesSearch this book
Previous: 9.1 Oracle8i and JavaChapter 9
Calling Java from PL/SQL
Next: 9.3 A Simple Demonstration
 

9.2 Getting Ready to Use Java in Oracle

Before you can call Java methods from within your PL/SQL programs you will need to do the following:

9.2.1 Installing Java

You will need to install a Java Development Kit ( JDK) 1.1.5 or above. You can do this by downloading a JDK from the Javasoft web site; Oracle also provides a JDK with Oracle8i. Here is the Javasoft URL:

http://www.javasoft.com/products/index.html

You will need to make sure to set the CLASSPATH so that the Java compiler (javac) can locate any references to your classes -- and to the Oracle classes. Visit the following URL to get more information about CLASSPATH:

http://www.javasoft.com/products/jdk/1.2/docs/tooldocs/win32/classpath.html#env var

You can see an online version of the Java language specification at:

http://java.sun.com/docs/books/jls/html/index.html

9.2.2 Building and Compiling Your Java Code

Many PL/SQL developers (including the author) have never worked with an object-oriented language of any kind, so coming up to speed on Java can be a bit of a challenge. In the short time in which I have studied and used Java, I have come to these conclusions:

It would be impossible to offer a comprehensive primer on Java in this chapter. There are many (many, many, many) books available on various aspects of Java, and a number of them are excellent. I would recommend that you check out the following:

In Section 9.9, "Examples, later in this chapter, as I demonstrate how to call Java methods from within PL/SQL, I will also take you step by step through the creation of relatively simple classes. You will find that, in many cases, this discussion will be all you need to get the job done.

9.2.3 Setting Oracle Privileges

Oracle8i has created two new roles to support Java security. For many Java-based operations within the database, you will not have to work with these roles. If, on the other hand, you want to interact with the operating system (to access or modify operating system files, for example), you need to be granted one of the following roles:

JAVASYSPRIV
JAVAUSERPRIV

You grant these roles as you would any other database role. For example, if I want to allow SCOTT to perform any kind of Java-related operation, I would issue this command from a SYSDBA account:

GRANT JAVASYSPRIV TO SCOTT;

If I want to place some restrictions on what the user can do with Java, I might execute this grant instead:

GRANT JAVAUSERPRIV TO SCOTT;

Here's one example of the difference between the two roles. To create a file through Java, I need the JAVASYSPRIV role; to read or write a file, I only need the JAVAUSERPRIV role. See the Oracle documentation for more details, including a table listing the different check methods of Java and which role is required to run those methods.

When the Aurora JVM is initialized, it installs an instance of java.lang.SecurityManager, the Java Security Manager. Each Oracle user has a dynamic ID, which will correspond to the session owner when you access the Java methods from within PL/SQL.

If a user lacking the sufficient privileges granted by one of these roles tries to execute an illegal operation, then the JVM will throw the java.lang.SecurityException. Here is what you would see in SQL*Plus:

ORA-29532: Java call terminated by uncaught Java exception:
           java.lang.SecurityException

When you run Java methods inside the database, different security issues can arise, particularly when interacting with the server-side filesystem or other operating system resources. Oracle follows one of the following two rules when checking I/O operations:


Previous: 9.1 Oracle8i and JavaOracle PL/SQL Programming Guide to Oracle 8i FeaturesNext: 9.3 A Simple Demonstration
9.1 Oracle8i and JavaBook Index9.3 A Simple Demonstration

The Oracle Library Navigation

Copyright (c) 2000 O'Reilly & Associates. All rights reserved.

Library Home Oracle PL/SQL Programming, 2nd. Ed. Guide to Oracle 8i Features Oracle Built-in Packages Advanced PL/SQL Programming with Packages Oracle Web Applications Oracle PL/SQL Language Pocket Reference Oracle PL/SQL Built-ins Pocket Reference