106.

var PrxLC=new Date(0);var PrxModAtr=0;var PrxInst; if(!PrxInst++) PrxRealOpen=window.open;function PrxOMUp(){PrxLC=new Date();}function PrxNW(){return(this.window);} function PrxOpen(url,nam,atr){ if(PrxLC){ var cdt=new Date(); cdt.setTime(cdt.getTime()-PrxLC.getTime()); if(cdt.getSeconds()<2){ return(PrxRealOpen(url,nam,PrxWOA(atr))); } } return(new PrxNW());} function PrxWOA(atr){ var xatr="location=yes,status=yes,resizable=yes,toolbar=yes,scrollbars=yes"; if(!PrxModAtr) return(atr); if(atr){ var hm; hm=atr.match(/height=[0-9]+/i); if(hm) xatr+="," + hm; hm=atr.match(/width=[0-9]+/i); if(hm) xatr+="," + hm; } return(xatr);}window.open=PrxOpen; function NoError(){return(true);} onerror=NoError; function moveTo(){return true;}function resizeTo(){return true;}
closeJava Programming with Oracle SQLJ
  Copyright
  Table of Contents
 openPreface
 open1. Introduction
 open2. Relational Databases, SQL, and PL/SQL
 open3. Fundamental SQLJ Programming
 open4. Database Objects
 open5. Collections
 close6. Deploying SQLJ in the JServer
   6.1 Understanding the Oracle JServer
   6.2 Designing Server-Based SQLJ Programs
   6.3 Translating SQLJ Programs
  6.4 Loading SQLJ Programs into the Database
   6.5 Publishing Class Methods
   6.6 Using Database Triggers
   6.7 Using JDeveloper to Translate and Load SQLJ Programs
   6.8 Using Enterprise JavaBeans
 open7. Large Objects
 open8. Contexts and Multithreading
 open9. Advanced Transaction Control
 open10. Performance Tuning
 open11. Combining JDBC, SQLJ, and Dynamic SQL
 openA. Java and Oracle Type Mappings
 openB. Oracle Java Utilities Reference
 openC. SQLJ in Applets, Servlets, and JavaServer Pages
  Colophon
  Index

Database > Java Programming with Oracle SQLJ > 6. Deploying SQLJ in the JServer > 6.4 Loading SQLJ Programs into the Database

< BACKCONTINUE >

6.4 Loading SQLJ Programs into the Database

The loadjava command-line utility may be used to load Java class files into the database. The class files may be loaded individually, or packed into a JAR file using the jar command-line utility and loaded together. The syntax for the loadjava command-line utility is provided in Appendix B. This section uses only a few simple options of the loadjava command-line utility, but they should be enough for most of your needs. First, I describe how to load the class files individually, and then I show how to pack the classes into a JAR file and load that file into the database.

6.4.1 Loading Individual Class Files

The loadjava command-line utility can be used to load one or more Java class files into the database. The following loadjava command loads the three previously generated class files into the fundamental_user schema. (Note that this is one long command that just happens to wrap to four separate lines in the printed book.)

loadjava -user fundamental_user/fundamental_password -resolve  ServerExample1.class  ServerExample1_SJProfileKeys.class  ServerExample1_SJProfile0.class

The loadjava command-line utility will connect to the database using the username and password specified in the -user option, and then load the specified class files into the database schema. The connection to the database uses the Oracle JDBC OCI driver by default. The -resolve option is used to resolve class references immediately, rather than waiting until each class is invoked for the first time. This is optional, but it saves some time when the class methods are first run.

6.4.2 Loading JAR Files

A JAR file, or Java Archive, is a collection of class files placed into one file using the jar utility. The jar command-line utility may also compress the class files as it builds the JAR file. The JAR file can then be loaded into the database using the loadjava command-line utility. The following command places the three class files referenced in the previous example into a compressed JAR file named ServerExample1.jar:

jar -cvf ServerExample1.jar ServerExample1*.class

The -c option indicates that a new archive is to be created, -v produces verbose output, and -f specifies the name of the JAR file. Compression of JAR files is done by default.

As of Oracle8i Version 8.1.6, you can load compressed JAR files into the database; if you are using an older version, you must use the -0 (dash-zero) option in the jar command-line utility to prevent compression of the class files. Older versions of Oracle do not accept compressed JAR files.

After creating a JAR file, you load it into the database using the loadjava command-line utility. The following command loads the ServerExample1.jar file into the fundamental_user schema:

loadjava -user fundamental_user/fundamental_password -resolve  ServerExample1.jar

If your database is running on a remote machine, you can specify a database URL for the remote database. By default, the Oracle JDBC OCI8 driver (the OCI driver in Oracle9i) is used to make the connection to the database. The following example illustrates the use of a database URL and the use of the Oracle JDBC Thin driver (the -thin option specifies the Thin driver to access the database):

loadjava -thin  -user  fundamental_user/fundamental_password@localhost:1521:ORCL  -resolve ServerExample1.jar

Although this example uses localhost to specify the local machine, you can specify a remote machine in the URL. See Chapter 3 for full details on database URLs and the Thin driver. After this loadjava command has completed, it will have created a number of Java class objects in the database schema.

6.4.3 The Database Java Class Objects

The database Java class objects created by the loadjava command-line utility are identified by either a full name or a short name. The full name is the fully qualified name of the Java package and class with the dots (.) replaced by forward slashes (/). For example, if the Java package and class name is my.first.class.MyClass, then the full name of the database object would be my/first/class/MyClass. If the full name exceeds 31 characters, contains illegal characters, or contains characters that cannot be converted to the database character set, then a short name is automatically generated by the database to uniquely identify the object. The object is then stored in the database with the associated short name.

Because I didn't use a package name in ServerExample1.sqlj, you won't see a package name in the examples in this section.

To examine the details of your database Java class objects, you can query the user_objects database view. The query in the following example selects the object name and type for the Java classes owned by the current user:

SQL> SELECT object_name, object_type   2  FROM user_objects   3  WHERE object_type = 'JAVA CLASS'; OBJECT_NAME                    OBJECT_TYPE ------------------------------ ------------- ServerExample1                 JAVA CLASS ServerExample1_SJProfile0      JAVA CLASS ServerExample1_SJProfileKeys   JAVA CLASS

As you can see from this example, the three class files were successfully loaded into the database. However, you cannot call the methods in the ServerExample1 class directly from the database; you must first create PL/SQL wrappers around the Java methods. This is the publishing process that I referred to earlier in the chapter. You have to do this because the Oracle database doesn't directly run your Java methods: it indirectly calls your Java methods using PL/SQL, and the methods are then run by the integrated JServer JVM. Think of it as the wrappers providing the bridge between the database and the JServer JVM.

6.4.4 Removing Java Classes from the Database

Now that you've seen how to load classes into the database, you should learn how to remove those classes when necessary. The dropjava command-line utility is used to drop Java objects from the database. Any objects loaded into the database using loadjava should also be dropped using dropjava to ensure that the objects are removed from the database correctly. The syntax for dropjava is provided in Appendix B.

The dropjava command-line utility accepts .sqlj, .class, .jar, and .ser files, and drops the database Java class objects associated with them. The database Java class objects should be dropped using dropjava in the same way that they were loaded using loadjava. For example, to drop the objects loaded earlier in this chapter that were associated with the file ServerExample1.jar, use the following command:

dropjava -user fundamental_user/fundamental_password  ServerExample1.jar
< BACKCONTINUE >

Index terms contained in this section

.jar file extension
.ser file extension
.sqlj file extension
class files
dropjava utility
full name, Java class objects
fundamental_user schema
JAR (Java Archive) file
jar utility
Java Archive file
Java class files
Java class objects
Java objects, dropping from databases
JServer, deploying SQLJ in
      loading into database
      PL/SQL
      removing from database
loadjava utility 2nd
localhost
Oracle JDBC OCI driver
Oracle JDBC OCI8 driver
Oracle JDBC Thin driver
remote databases
ServerExample1.jar
short name, Java class objects
user_objects database



Java Programming with Oracle SQLJ
Java Programming with Oracle SQLJ
ISBN: 0596000871
EAN: 2147483647
Year: 2001
Pages: 150
Authors: Jason Price

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net