Figure 22-3. Loading Java elements into Oracle
Here is the syntax:
loadjava {-user | -u} username/password[@database] [-option_name [-option_name] ...] filename [filename ]...where option_name can be one or more of many options, some of which are listed below:
| debug | {definer | d} | {encoding | e} encoding_scheme_name | {force | f} | {grant | g} {username | role_name}[,{username | role_name}]... | {oci8 | o} | {resolve | r} | {resolver | R} "resolver_spec" | {schema | S} schema_name | {synonym | s} | {thin | t} | {verbose | v} | {nousage} | {noverify}}On the command line, you can enter the names of Java source, class, and resource files, SQLJ input files (.sqlj files), and uncompressed .jar files and .zip archives, in any order.
The following command, for example, loads the JFile class into the SCOTT schema:
You can run this command from within a DOS window on Windows platforms or from the command line in a Unix session. You can also execute it from within SQL*Plus as shown:
host loadjava -user scott/tiger -oci8 -resolve JFile.classTo make it easier to load Java resources into Oracle, I created a file named lj.bat for Windows as follows:
javac %1.javaloadjava -user %2 -oci8 -resolve %1.javaNow I can compile and load a Java class in one step:
D:\Java> lj scott/tiger JFileHere are some things to keep in mind about loadjava. To display a help screen, use this syntax:
loadjava {-help | -h}In a list of options or files, names must be separated only by spaces:
-force, -resolve, -thin // No-force -resolve -thin // YesIn a list of users or roles, however, names must be separated only by commas:
SCOTT, PAYROLL, BLAKE // NoSCOTT,PAYROLL,BLAKE // YesTable 22-2 summarizes the common loadjava command-line options.
Table 22-2. Common loadjava options | |
Option | Description |
-debug | Generates debug information. This option is equivalent to javac -g. |
-definer | Specifies that the methods of uploaded classes will execute with the privileges of their definer, not their invoker. (By default, methods execute with the privileges of their invoker.) Different definers can have different privileges, and an application can have many classes, so make sure the methods of a given class execute only with the privileges they need. |
-encoding | Sets (or resets) the -encoding option in the database table JAVA$OPTIONS to the specified value, which must be the name of a standard JDK encoding scheme (the default is "latin1"). The compiler uses this value, so the encoding of uploaded source files must match the specified encoding. Refer to Section 22.7.2 for information on how this object is created and used. |
-force | Forces the loading of Java class files, whether or not they have been loaded before. By default, previously loaded class files are rejected. You cannot force the loading of a class file if you previously loaded the source file. You must drop the source schema object first. |
-grant | Grants the EXECUTE privilege on uploaded classes to the listed users or roles. (To call the methods of a class directly, users must have the EXECUTE privilege.) This option is cumulative. Users and roles are added to the list of those having the EXECUTE privilege. To revoke the privilege, either drop and reload the schema object without specifying -grant, or use the SQL REVOKE statement. To grant the privilege on an object in another user's schema, you must have the CREATE PROCEDURE WITH GRANT privilege. |
-oci8 | Directs loadjava to communicate with the database using the OCI JDBC driver. This option (the default) and -thin are mutually exclusive. When calling loadjava from a client-side computer that does not have Oracle installed on it, use the -thin option. |
-resolve | After all class files on the command line are loaded and compiled (if necessary), resolves all external references in those classes. If this option is not specified, files are loaded but not compiled or resolved until runtime. Specify this option to compile (if necessary) and resolve a class that was loaded previously. You need not specify the -force option because resolution is done independently, after loading. |
-resolver | Binds newly created class schema objects to a user-defined resolver spec. Because it contains spaces, the resolver spec must be enclosed in double quotes. This option and -oracleresolver (the default) are mutually exclusive. |
-schema | Assigns newly created Java schema objects to the specified schema. If this option is not specified, then the logon schema is used. You must have the CREATE ANY PROCEDURE privilege to load into another user's schema. |
-synonym | Creates a public synonym for uploaded classes, making them accessible outside the schema into which they are loaded. To specify this option, you must have the CREATE PUBLIC SYNONYM privilege. If you specify this option for source files, it also applies to classes compiled from those source files. |
-thin | Directs loadjava to communicate with the database using the thin JDBC driver. This option and -oci8 (the default) are mutually exclusive. When calling loadjava from a client-side computer that does not have Oracle installed on it, use the -thin option. |
-verbose | Enables the verbose mode, in which progress messages are displayed. |
As you can probably imagine, there are various nuances of using loadjava, such as whether to load individual classes or compressed groups of elements in a .zip or .jar file. The Oracle documentation contains more information about the loadjava command.