BC remote Oracle DBA - Call (800) 766-1884  
Oracle Consulting Oracle Training Development

Remote DBA

Remote DBA Plans  

Remote DBA Service

Remote DBA RAC

Remote DBA Oracle Home
Remote DBA Oracle Training
Remote DBA SQL Tuning Consulting
Remote DBA Oracle Tuning Consulting
Remote DBA Data Warehouse Consulting
Remote DBA Oracle Project Management
Remote DBA Oracle Security Assessment
Remote DBA Unix Consulting
Burleson Books
Burleson Articles
Burleson Web Courses
Burleson Qualifications
Oracle Links
Remote DBA Oracle Monitoring
Remote DBA Support Benefits
Remote DBA Plans & Prices
Our Automation Strategy
What We Monitor
Oracle Apps Support
Print Our Brochure
Contact Us (e-mail)
Oracle Job Opportunities
Oracle Consulting Prices





Remote DBA services

Remote DBA Support

Remote DBA RAC

Remote DBA Reasons

Remote Oracle Tuning

Remote DBA Links

Oracle DBA Support

Oracle DBA Forum

Oracle Disaster

Oracle Training

Oracle Tuning

Oracle Training

 Remote DBA SQL Server

Remote MSSQL Consulting

Oracle DBA Hosting

Oracle License Negotiation








Administration of Java Objects

Oracle Tips by Burleson Consulting

In Oracle 8i, Java must first be loaded to make use of it; Oracle9i loads the Java VM automatically through the LoadJava utility, which is described next.

Using LoadJava

Using a built-in PL/SQL package named LoadLobs, the LoadJava utility uploads Java files into a BLOB column in the table create$java$lob$table, which the utility creates in the logon schema. Then it uses the SQL CREATE JAVA statement to load the Java files into the RDBMS.

LoadJava also accepts SQLJ input files (.sqlj files). To process them, it invokes the Server SQLJ Translator, which outputs Java sources and serialized objects for SQLJ profiles (.ser files). Then it invokes the Java compiler, which compiles the Java sources into standard binaries. (For more information, refer to the numerous Java references on the documentation Web site.)

Using a client-side JDBC driver, LoadJava can upload individual Java sources and binaries, SQLJ input files, and entire Java archives (JARs). However, it cannot upload individual resources, so you must put them in a JAR. You can enter .java, .class, .jar, and .sqlj files on the command line in any order. The syntax is:


[{-h | -help}]
[{-v | -verbose}]
[{-f | -force}]
[{-r | -resolve}]
[{-a | -andresolve}]
[{-S | -schema} schema_name]
[{-d | -definer}]
[{-s | -synonym}]
[{-g | -grant} {username | role_name}[, {username | role_name}]...]
[{-R | -resolver} "resolver_spec"]
[{-e | -encoding} encoding_scheme_name]
[{-t | -thin} | {-o | -oci81}]
[{-u | -user} username/password@host_name:port_number:database_sid]
{filename.java | filename.class | filename.jar | filename.sqlj} ...


resolver_spec. Specifies schemas to be searched (in the order listed) for referenced Java fullnames. Its syntax is:

((match_string schema_name) (match_string schema_name) ...)

where match_string is a Java fullname; the wildcard, an asterisk (*),which matches any name; or a combination, such as home/java/bin/*; and where schema_name is the name of a schema or the wildcard  (which indicates that names matching the pattern need not be resolved). The default resolver_spec follows:

((* definer's_schema) (* public))

The following list presents the LoadJava command-line options:




Displays a help screen that lists all the command-line options. 


Enables verbose mode, in which progress messages are displayed.


Forces the loading of Java classes whether or not they have been loaded before. By default, previously loaded classes are rejected. You cannot force the loading of a binary if you previously loaded the source. You must drop the source first.  


Compiles all uploaded sources, then resolves external references in uploaded Java classes. Otherwise, sources are compiled and classes are resolved at runtime or when the Java virtual machine (JVM) needs the definitions to resolve other classes. If errors occur during name resolution, they are displayed.


Works like the -r option except that each uploaded source is compiled and resolved separately. This lets you replace a class that might invalidate other classes. 


Assigns newly created Java library units to the specified schema. Otherwise, the logon schema is used.  


Creates public synonyms for uploaded classes. To specify this option, you must have the CREATE PUBLIC  SYNONYM privilege.


Specifies that the methods of uploaded classes will execute with the privileges of their definer, not their invoker.


Grants the EXECUTE privilege on uploaded classes and resources to the listed users and/or roles. (To call the methods of a class directly, users must have the EXECUTE privilege.)


Specifies a resolver spec, which is bound to newly created Java library units. Because it contains spaces, the resolver spec must be enclosed by double quotation marks. 


Sets the encoding option in the database table java$options to the specified value, which must be a standard JDK encoding-scheme name. The encoding of uploaded sources must match the specified encoding.

-t | -o    

Selects the client-side JDBC driver used to communicate with Oracle. You can choose the Thin JDBC Driver (the default) or the OCI JDBC Driver. For information about these drivers, see the JDBC reference on the documentation Web site.


Specifies a database connect string without spaces. The string includes a user name, password, host-computer name, port number, and database system identifier. If this option is not specified, the string defaults to internal/oracle@localhost:1521:orcl.   

Caution: LoadJava uses the hash table java$class$md5$table to track the loading of Java library units into a schema (md5 refers to RSA Data Security痴 MD5 Message-Digest Algorithm, which does the hashing). If you use LoadJava to load a Java library unit, you must use DropJava to drop the unit. Otherwise, the table will not be updated properly.  Also, if you use the SQL DROP JAVA statement to drop a Java class, and then use LoadJava to upload the same class, you must specify the force (-f) command-line option. Otherwise, the upload fails.

LoadJava Examples  

In the first example, LoadJava uploads archived Java binaries and resources from an OS file system (> is the prompt). The utility reads the JAR files, stores each binary or resource in a database row keyed by the filename of the class or resource, then uses the SQL CREATE JAVA statement to load the Java files into the RDBMS.

> loadjava -u scott/tiger@myComputer:1521:orcl managers.jar

In the next example, operating in verbose mode, LoadJava uploads and resolves a Java source file. The force (-f) option forces the loading of the file. The resolve option (-r) compiles the file and resolves external references; also, by reporting resolution errors, it helps to identify missing classes.

> loadjava -v -f -r -u scott/tiger@myComputer:1521:orcl Agent.java

Load Lobs package already installed:

loading  : Agent

creating : Agent

resolving: Agent

In the following example, a name resolver is specified:

> loadjava -R "((/home/java/bin/* scott) (* public))"
-u scott/tiger@myComputer:1521:orcl Swapper.class

If the path to a file begins with a slash, LoadJava prefixes the word ROOT to the Java fullname, as the following example shows:

> loadjava -v -f -u scott/tiger@myComputer:1521:orcl

Load Lobs package already installed:

loading  : ROOT/routines/java/src/Alerter
creating : ROOT/routines/java/src/Alerter

Checking Upload Results

To check upload results, you can query the database view user_objects, which contains information about schema objects owned by the user (Scott, in this case). For example, the following SQL*Plus script formats and displays useful information about uploaded Java sources, binaries, and resources:

PROMPT A)ll or J)ava only?
  choice CHAR(1) := UPPER('&x');
  printable BOOLEAN;
  bad_choice EXCEPTION;

  IF choice NOT IN ('A', 'J') THEN RAISE bad_choice; END IF;
  DBMS_OUTPUT.PUT_LINE('Object Name                    ' ||
    'Object Type   Status  Timestamp');
  DBMS_OUTPUT.PUT_LINE('覧覧覧覧覧覧覧 ' ||
    '覧覧覧- 覧- 覧覧覧覧');
  FOR i IN (SELECT object_name, object_type, status, timestamp
    FROM user_objects ORDER BY object_type, object_name)
    /* Exclude objects generated for LoadJava and DropJava. */
    printable := i.object_name NOT LIKE 'SYS_%'
      AND i.object_name NOT LIKE 'CREATE$%'
      AND i.object_name NOT LIKE 'JAVA$%'
      AND i.object_name NOT LIKE 'LOADLOBS';
    IF choice = 'J' THEN
      printable := i.object_type LIKE 'JAVA %';
    END IF;
    IF printable THEN
      DBMS_OUTPUT.PUT_LINE(RPAD(i.object_name,31) ||
        RPAD(i.object_type,14) ||
        RPAD(i.status,8) || SUBSTR(i.timestamp,1,16));
    END IF;
  WHEN bad_choice THEN
    DBMS_OUTPUT.PUT_LINE('Bad choice');

You can choose to display all your schema objects or only the Java objects:

SQL> @usr_obj
A)ll or J)ava only?
Choice: a

Object Name                   Object Type   Status  Timestamp
Alerter                       JAVA CLASS    VALID   1998-10-08:13:42
POManager                     JAVA CLASS    VALID   1998-10-08:17:14
Alerter                       JAVA Source   VALID   1998-10-08:13:42
POManager                     JAVA Source   VALID   1998-10-08:17:11
BONUS                         TABLE         VALID   1998-10-08:14:02
DEPT                          TABLE         VALID   1998-10-08:14:02
EMP                           TABLE         VALID   1998-10-08:14:02
SALGRADE                      TABLE         VALID   1998-10-08:14:02

SQL> @usr_obj
A)ll or J)ava only?
Choice: j

Object Name                   Object Type   Status  Timestamp
Alerter                       JAVA CLASS    VALID   1998-10-08:13:42
POManager                     JAVA CLASS    VALID   1998-10-08:17:14
Alerter                       JAVA Source   VALID   1998-10-08:13:42
POManager                     JAVA Source   VALID   1998-10-08:17:11

The column object_name stores Java fullnames. However, if a name is longer than 30 characters or contains an untranslatable character, the shortname is stored instead. To convert shortnames to fullnames, you can use the function longname in the utility package DBMS_JAVA, as follows:

SQL> SELECT dbms_java.longname(object_name), ... FROM user_objects;

Table 7.1 describes all the columns in database view user_objects.

Table 7.1   USER_OBJECTS View Columns

Column Name





Name of the object



Name of any subobject (a partition, for example)



 Object number of the object



Object number of the segment that contains the object



Type of object (a table or index, for example) 



 Date on which the object was created



Date of the last DDL operation on the object



Character string containing the date and time the object was created



Status (valid or invalid) of the object



Indicator (y/n) of whether or not the current session sees only the data that it stores in the object



Indicator of whether or not the name of the object was generated by the system



Indicator of whether or not this is a secondary object created for domain indexes

See Code Depot for Full Scripts

This is an excerpt from Mike Ault, bestselling author of "Oracle 10g Grid and Real Application Clusters".

You can buy it direct from the publisher for 30%-off and get instant access to the code depot of Oracle tuning scripts.

Expert Remote DBA

BC is America's oldest and largest Remote DBA Oracle support provider.  Get real Remote DBA experts, call
BC Remote DBA today.



Remote DBA Service

Oracle Tuning Book


Advance SQL Tuning Book 

BC Oracle support

Oracle books by Rampant

Oracle monitoring software







BC Remote Oracle Support

Remote DBA

Remote DBA Services

Copyright ゥ 1996 -  2013 by Burleson. All rights reserved.

Oracleョ is the registered trademark of Oracle Corporation.

Hit Counter