This chapter provides a description of the DBMS_JAVA
package. The functions and procedures in this package provide an entry point for accessing RDBMS functionality from Java.
FUNCTION longname (shortname VARCHAR2) RETURN VARCHAR2
The function returns the fully qualified name of the specified Java schema object. Because Java classes and methods can have names exceeding the maximum SQL identifier length, Oracle JVM uses abbreviated names internally for SQL access. This function returns the original Java name for any truncated name. An example of this function is to print the fully qualified name of classes that are invalid:
SELECT dbms_java.longname (object_name) FROM user_objects WHERE object_type = 'JAVA CLASS' AND status = 'INVALID';
FUNCTION shortname (longname VARCHAR2) RETURN VARCHAR2
You can specify a full name to the database by using the shortname()
routine of the DBMS_JAVA
package, which takes a full name as input and returns the corresponding short name. This is useful when verifying that your classes loaded by querying the USER_OBJECTS
view.
FUNCTION get_compiler_option(name VARCHAR2, optionName VARCHAR2) RETURN VARCHAR2
This function returns the value of the option specified through the optionName
parameter. It is one of the functions used to control the options of the Java and SQLJ compiler supplied with Oracle Database.
PROCEDURE set_compiler_option(name VARCHAR2, optionName VARCHAR2, value VARCHAR2)
This procedure is used to set the options of the Java and SQLJ compiler supplied with Oracle Database.
PROCEDURE reset_compiler_option(name VARCHAR2, optionName VARCHAR2)
This procedure is used to reset the specified compiler option to the default value.
FUNCTION resolver (name VARCHAR2, owner VARCHAR2, type VARCHAR2) RETURN VARCHAR2
This function returns the resolver specification for the object specified in name
and in the schema specified in owner
, where the object is of the type specified in type
. The caller must have EXECUTE
privilege and have access to the given object to use this function.
The name
parameter is the short name of the object.
The value of type
can be either SOURCE
or CLASS
.
If there is an error, then NULL
is returned. If the underlying object has changed, then ObjectTypeChangedException
is thrown.
You can call this function as follows:
SELECT dbms_java.resolver('tst', 'SCOTT', 'CLASS') FROM DUAL;
This would return:
DBMS_JAVA.RESOLVER('TST','SCOTT','CLASS') ----------------------------------------- ((* SCOTT)(* PUBLIC))
FUNCTION derivedFrom (name VARCHAR2, owner VARCHAR2, type VARCHAR2) RETURN VARCHAR2
This function returns the source name of the object specified in name
of the type specified in type
and in the schema specified in owner
. The caller must have EXECUTE
privilege and have access to the given object to use this function.
The name
parameter, as well as the returned source name, is the short name of the object.
The value of type
can be either SOURCE
or CLASS
.
If there is an error, then NULL
is returned. If the underlying object has changed, then ObjectTypeChangedException
is thrown.
The returned value will be NULL
if the object was not compiled in Oracle JVM.
You can call this function as follows:
SELECT dbms_java.derivedFrom('tst', 'SCOTT', 'CLASS') FROM DUAL;
This would return:
DBMS_JAVA.DERIVEDFROM('TST','SCOTT','CLASS') ----------------------------------------- tst
FUNCTION fixed_in_instance (name VARCHAR2, owner VARCHAR2, type VARCHAR2) RETURN NUMBER
This function returns the permanently kept status for object specified in name
of the type specified in type
and in the schema specified in owner
. The caller must have EXECUTE
privilege and have access to the given object to use this function.
The name
parameter is the short name for the object.
The value of type
can be either of RESOURCE
, SOURCE
, CLASS
, or SHARED_DATA
.
The number returned is either 0
, indicating the status is not kept, or 1
, indicating the status is kept.
You can call this function as follows:
SELECT dbms_java.fixed_in_instance('tst', 'SCOTT', 'CLASS') FROM DUAL;
This would return:
DBMS_JAVA.FIXED_IN_INSTANCE('TST','SCOTT','CLASS') ----------------------------------------- 0
Consider the following statement:
SELECT dbms_java.fixed_in_instance('java/lang/String', 'SYS', 'CLASS') FROM DUAL;
This would return:
DBMS_JAVA.FIXED_IN_INSTANCE('JAVA/LANG/STRING','SYS','CLASS') ------------------------------------------------------------- 1
PROCEDURE set_output (buffersize NUMBER)
This procedure redirects the output of Java stored procedures and triggers to the DBMS_OUTPUT
package.
PROCEDURE start_debugging(host VARCHAR2, port NUMBER, timeout NUMBER)
This procedure is used to start the debug agent on the specified host at the specified port
PROCEDURE restart_debugging(timeout NUMBER)
This procedure is used to restart the debug agent.
PROCEDURE export_source(name VARCHAR2, schema VARCHAR2, blob BLOB) PROCEDURE export_source(name VARCHAR2, blob BLOB) PROCEDURE export_source(name VARCHAR2, clob CLOB)
These procedures are used to export the Java source as a Java source schema object to Oracle Database. The source is specified through the name
parameter. The source can be exported into a BLOB
or CLOB
object. The internal representation of the source uses the UTF8 format, so that format is used to store the source in the BLOB
as well. The source schema object is created in the specified schema. If the schema is not specified then the current schema is used.
PROCEDURE export_class(name VARCHAR2, schema VARCHAR2, blob BLOB) PROCEDURE export_class(name VARCHAR2, blob BLOB)
These procedures are used to export Java classes specified through the name
parameter as Java class schema objects to Oracle Database. You cannot export a class into a CLOB
object, only into a BLOB
object. If the schema is specified, then the class schema object is created in this schema, else in the current schema.
PROCEDURE export_resource(name VARCHAR2, schema VARCHAR2, blob BLOB) PROCEDURE export_resource(name VARCHAR2, blob BLOB) PROCEDURE export_resource(name VARCHAR2, schema VARCHAR2, clob CLOB) PROCEDURE export_resource(name VARCHAR2, clob CLOB)
The resource specified through the name parameter is exported to Oracle Database as a resource schema object in the schema specified through the schema
parameter. If the schema is not specified then the current schema is used. The resource can be exported into either a CLOB
object or BLOB
object.
PROCEDURE loadjava(options VARCHAR2) PROCEDURE loadjava(options VARCHAR2, resolver VARCHAR2)
These procedures enable you to load classes in to the database using a call, rather than through the loadjava
command-line tool. You can call this procedure within your Java application as follows:
CALL dbms_java.loadjava('... options...');
The options are identical to those specified on the command line. Each option should be separated by a space. Do not separate the options with a comma. The only exception to this is the loadjava -resolver
option, which contains spaces. For -resolver
, specify all other options first, separate these options by a comma, and then specify the -resolver
options, as follows:
CALL dbms_java.loadjava('... options...', 'resolver_options');
Do not specify the -thin
, -oci
, -user
, and -password
options, because they relate to the database connection. The output is directed to System.err
. The output typically goes to a trace file, but can be redirected.
PROCEDURE dropjava(options VARCHAR2)
This procedure enables you to drop classes within the database using a call, rather than through the dropjava
command-line tool. You can call this procedure within your Java application as follows:
CALL dbms_java.dropjava('... options...');
PROCEDURE grant_permission(grantee VARCHAR2, permission_type VARCHAR2, permission_name VARCHAR2, permission_action VARCHAR2)
This method is used to grant permission to specific users or roles.
PROCEDURE restrict_permission(grantee VARCHAR2, permission_type VARCHAR2, permission_name VARCHAR2, permission_action VARCHAR2)
This method is used to specify limitations or exceptions to general rules.
PROCEDURE grant_policy_permission(grantee VARCHAR2, permission_schema VARCHAR2, permission_type VARCHAR2, permission_name VARCHAR2)
This method is used to grant and limit PolicyTablePermission
.
PROCEDURE revoke_permission(permission_schema VARCHAR2, permission_type VARCHAR2, permission_name VARCHAR2, permission_action VARCHAR2)
This method is used to disable a granted permission.
See Also:
"Enabling or Disabling Permissions"PROCEDURE disable_permission(key NUMBER)
This method is used to disable a granted permission.
See Also:
"Enabling or Disabling Permissions"PROCEDURE enable_permission(key NUMBER)
This method is used to enable a permission.
See Also:
"Enabling or Disabling Permissions"PROCEDURE delete_permission(key NUMBER)
This method is used to delete a granted permission.
See Also:
"Enabling or Disabling Permissions"procedure set_preference(user VARCHAR2, type VARCHAR2, abspath VARCHAR2, key VARCHAR2, value VARCHAR2)
This procedure inserts or updates a row in the SYS:java$prefs$
table as follows:
CALL dbms_java.set_preference('SCOTT', 'U', '/my/package/method/three', 'windowsize', '22:32');
The user
parameter specifies the name of the schema to which the preference should be attached. If the logged in schema is not SYS
, then user
must specify the current logged in schema or the INSERT
will fail. The type
parameter can take either the value U
, indicating user preference, or S
, indicating system preference. The abspath
parameter specifies the absolute path for the preference. key
is the preference key used for the lookup, and value
is the value of the preference key.