loadjava

 

The loadjava  utility (Oracle 8.1.5 and up) loads Java source and class files into the database.  When class files are created in a conventional manner, outside the database, loadjava is used to get them into the database.

 

loadjava requires two database privileges to load java objects into your own schema: CREATE PROCEDURE and CREATE TABLE.  To load Java objects into a schema other than the currently connected user, CREATE ANY PROCEDURE and CREATE ANY TABLE privileges are required.

 

This example will use a simple Java program that will be compiled outside of Oracle and then loaded into the database.

 

public class SimpleJava {

  

   public void main(String[] args) {

      System.out.println("Here we are");

   }

 

From DOS or  UNIX :

 

C:\oracle9i\bin>javac SimpleJava.java

 

C:\oracle9i\bin>loadjava -user scott/tiger SimpleJava.class

 

The class file is now loaded into the database and visible from the dba_objects view with an object type of JAVA CLASS.

 

From SQL*Plus, create the PL/SQL wrapper to invoke the newly loaded Java class:

SQL> create or replace procedure call_simplejava

  2  as language java

  3  name 'SimpleJava.showMessage()';

  4  /

 

Execute the code from SQL*Plus:

 

SQL> set serveroutput on;

SQL> call dbms_java.set_output(50);

 

Call completed.

 

SQL> execute call_simplejava;

Here we are

 

PL/SQL procedure successfully completed.

 

In this example, the Java class file was loaded into the database.  The Java source file can also be loaded.  But, both the source and class files cannot be loaded at the same time.

 

C:\oracle9i\bin>loadjava -user scott/tiger SimpleJava.java

 

If loading many Java class files at one time, it is advisable to put them in a JAR file and load them into the database at one time, since the loadjava program will also load JAR files.   A JAR file is a group of Java class files lumped into one file, a format similar to TAR (on  UNIX ) and WinZip (on Windows).   The contents of a JAR file can be viewed using these popular utilities.  Java developers prefer to distribute a few JAR files rather than many individual Java class files.

 

loadjava provides many command line options for the Java developer.  The complete list can be viewed by typing loadjava at the command line.

 
 
Copyright 2003, Rampant Tech Press, Dave Moore - All Rights Reserved. All product names and trademarks are property of their respective owners.