Oracle PL/SQL Programming Guide to Oracle 8i Features

Oracle PL/SQL Programming Guide to Oracle 8i FeaturesSearch this book
Previous: 9.5 Using dropjavaChapter 9
Calling Java from PL/SQL
Next: 9.7 Using DBMS_JAVA and DBMS_JAVA_TEST

9.6 Managing Java in the Database

This section explores in more detail issues related to the way Java elements are stored in the database, and how you can manage those elements.

9.6.1 The Java Namespace in Oracle

Oracle stores each Java class in the database as a schema object. The name of that object is derived from (but is not the same as) the fully qualified name of the class; this name includes the names of any containing packages. The full name of the class OracleSimpleChecker, for example, is as follows:


In the database, however, the full name of the Java schema object would be:


Once stored in the Oracle RDBMS, in other words, slashes replace dots.

An object name in Oracle, whether it is the name of a database table or a Java class, cannot be longer than 30 characters. Java does not have the same restriction; you can have much longer names. Oracle will allow you to load a Java class into Oracle with a name of up to 4000 characters. If the Java element name has more than 30 characters, Oracle will automatically generate a valid (less than 31 characters) alias for that element.

But don't worry! You never have to reference that alias. You can, instead, continue to use the real name for your Java element in your code. Oracle will map that long name automatically to its alias (the schema name) when necessary.

9.6.2 Examining Loaded Java Elements

Once you have loaded Java source, class, and resource elements into the database, information about those elements is available in several different data dictionary views, as shown in Table 9.4.

Table 9.4: Class Information in Data Dictionary Views






Contains header information about your objects of JAVA SOURCE, JAVA CLASS, and JAVA RESOURCE types




Contains any compilation errors encountered for your objects


Contains the source code for your Java source if and only if you used the CREATE JAVA SOURCE command to create the Java schema object

You can write queries against these views or you can build programs to access the information in a variety of useful ways. For example, here is a query that shows me all of the Java-related objects in my schema:

/ *Filename on companion disk: myjava.pkg */
COLUMN object_name FORMAT A30
SELECT object_name, object_type, status, timestamp
  FROM user_objects
 WHERE (object_name NOT LIKE 'SYS_%'
         AND object_name NOT LIKE 'CREATE$%'
         AND object_name NOT LIKE 'JAVA$%'
         AND object_name NOT LIKE 'LOADLOB%')
   AND object_type LIKE 'JAVA %'
 ORDER BY object_type, object_name;

The WHERE clause filters out those objects created by Oracle for managing Java objects. Here is some sample output:

SQL> @showjava
---------------------   ------------ ------- -------------------
Hello                   JAVA CLASS   VALID   1999-05-19:16:42:27
JFile2                  JAVA CLASS   VALID   1999-05-26:17:07:11
JFile3                  JAVA CLASS   VALID   1999-05-27:12:53:46
plsolutions/java/putLn  JAVA SOURCE  VALID   1999-05-19:16:30:29

The myjava.pkg file on the companion disk contains a packaged version of this query, allowing you to view your Java objects with this procedure call:

SQL> exec myjava.showobjects

The following lets you see a list of all the Java elements whose names start with OE:

SQL> exec myjava.showobjects ('OE%')

The USER_OBJECTS view's object_name column contains the full names of Java schema objects, unless the name is longer than 30 characters or contains an untranslatable character from the Unicode character set. In this case, the short name is displayed in the object_name column. To convert short names to full names, you can use the LONGNAME function in the utility package DBMS_JAVA, which is explored in the next section.

Here are some things to keep in mind about Java schema elements stored in the database:

Previous: 9.5 Using dropjavaOracle PL/SQL Programming Guide to Oracle 8i FeaturesNext: 9.7 Using DBMS_JAVA and DBMS_JAVA_TEST
9.5 Using dropjavaBook Index9.7 Using DBMS_JAVA and DBMS_JAVA_TEST

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