| General Information |
| Purpose |
Provides a PL/SQL interface for accessing database functionality from Java. |
| Source |
{ORACLE_HOME}/rdbms/admin/initdbj.sql
Because ... note this package contains 101 functions and procedures ... this page is not complete |
| Dependencies |
| ALL_JAVA_COMPILER_OPTIONS |
DBMS_OUTPUT |
| DBA_JAVA_COMPILER_OPTIONS |
DBMS_PIPE |
| DBA_OBJECTS_AE |
GET_ERROR$ |
| DBJ_SHORT_NAME |
JVMRJBC |
| DBMS_JAVA_DEFINERS |
PLITBLM |
| DBMS_JAVA_TEST |
SDO_NET |
| DBMS_JVM_EXP_PERMS |
USER_JAVA_COMPILER_OPTIONS |
|
| Exceptions |
| Error Code |
Reason |
| ORA-29532 |
Untrapped Java Exception |
|
| Security Model |
Execute is granted to PUBLIC. Runs as AUTHID CURRENT_USER |
| Subprograms |
|
| |
| DBMS_FEATURE_OJVM |
| Undocumented |
dbms_java.dbms_feature_ojvm(
ojvm_boolean OUT NUMBER,
aux_count OUT NUMBER,
ojvm_info OUT CLOB); |
| TBD |
| |
DBMS_FEATURE_SYSTEM_OJVM  |
| Undocumented |
dbms_java.dbms_feature_system_ojvm(
ojvm_boolean OUT NUMBER,
aux_count OUT NUMBER,
ojvm_info OUT CLOB); |
| TBD |
| |
| DECODE_NATIVE_COMPILER_OPTION |
| Undocumented |
dbms_java.decode_native_compiler_option(
optionName IN VARCHAR2,
value IN VARCHAR2)
RETURN VARCHAR2; |
| TBD |
| |
| DROPJAVA |
| Drops classes within the database using a call, rather than through the dropjava command-line tool |
dbms_java.dropjava(options IN VARCHAR2) AS LANGUAGE JAVA NAME 'oracle.aurora.server.tools.loadjava.DropJavaMain.serverMain(java.lang.String)'; |
| exec dbms_java.dropjava('-s rdbms/jlib/schagent.jar'); |
| |
DUMP_NATIVE_MACHINE_CODE  |
| Dump the native code (if available) for the specified method to trace |
dbms_java.dump_native_machine_code(
classname IN VARCHAR2,
methodname IN VARCHAR2,
methodsig IN VARCHAR2); |
| TBD |
| |
| GETVERSION |
| Retrieves the database version |
dbms_java.getVersion RETURN VARCHAR2; |
SELECT dbms_java.getVersion
FROM dual; |
| |
| GRANT_PERMISSION |
Grants Property Permissions. Create an active row in the policy table granting the Permission as specified to grantee/
This demo courtesy of Ralph Mintel. It has been tested against 11.2.0.1 is is valid. |
dbms_java.grant_permission(
grantee IN VARCHAR2,
permission_type IN VARCHAR2,
permission_name IN VARCHAR2,
permission_action IN VARCHAR2,
key OUT NUMBER)
AS LANGUAGE JAVA NAME 'oracle.aurora.rdbms.security.PolicyTableManager.grant(
java.lang.String, java.lang.String, java.lang.String, java.lang.String, long[])'; |
-- ==============================================
-- Oracle Java Functions
-- Oracle dba_java_policy
-- Variation on Tom Kyte's java system properties.
-- Ralph Mintel Mar. 21, 2008
-- ==============================================
col name format a40
col value format a60
col id format 999
-- =============================================
-- Function to retrieve all of the java properties.
-- =============================================
CREATE OR REPLACE FUNCTION jp RETURN VARCHAR2 IS LANGUAGE JAVA
NAME 'java.lang.System.getProperties()
RETURN java.lang.String';
/
-- =============================================
-- the following will probably fail with ORA-29532:
-- Java call terminated by uncaught Java exception:
-- java.security.AccessControlException:
-- (java.util.PropertyPermission * read,write)
-- has not been granted to UWCLASS.
-- =============================================
SELECT jp() FROM dual;
-- =============================================
-- Grant java PropertyPermission...
-- =============================================
conn / as sysdba
desc dba_java_policy;
CALL dbms_java.grant_permission('UWCLASS', 'SYS:java.util.PropertyPermission', '*', 'read,write' );
-- =============================================
-- Back to our user...
-- =============================================
conn uwclass/uwclass
col name format a40
col value format a60
col id format 999
SELECT jp() FROM dual;
-- =============================================
-- Create a table for these java properties...
-- =============================================
CREATE TABLE java_properties (
rid NUMBER,
name VARCHAR2(40),
value VARCHAR2(660) DEFAULT NULL);
-- =============================================
-- Insert each java property name-value pair into a table.
--
-- The entire block of properties starts with '{'
-- and ends with '}'.
--
-- The property name=value sets are comma delimited.
-- '=' separates the name and value.
-- =============================================
set serveroutput on
DECLARE
s VARCHAR2(4000);
x PLS_INTEGER;
y PLS_INTEGER;
id PLS_INTEGER := 1;
lastone BOOLEAN := FALSE;
xname_size PLS_INTEGER;
xvalue_start PLS_INTEGER;
xvalue_size PLS_INTEGER;
BEGIN
SELECT jp() INTO s FROM dual;
x := 2; /* starting column in s, to ignore the opening { */
y := 1; /* column where comma separator is found. */
LOOP
y := INSTR(s, ',', x, 1);
IF (y < 1) THEN
y := INSTR(s, '}', x, 1);
lastone := true;
END IF;
dbms_output.put_line(SUBSTR(s, x, y-x));
xname_size := INSTR(s, '=', x, 1) - x;
xvalue_start := x + xname_size + 1;
xvalue_size := INSTR(s, ',', xvalue_start, 1) - xvalue_start;
IF (lastone) THEN
xvalue_size := INSTR(s, '}', xvalue_start, 1) - xvalue_start;
END IF;
IF (xvalue_size > 0) THEN
INSERT INTO java_properties
(rid, name, value)
VALUES (
id, SUBSTR(s, x, xname_size), SUBSTR(s, xvalue_start, xvalue_size));
ELSE
INSERT INTO java_properties (id, name)
(rid, name)
VALUES
(id, SUBSTR(s, x, xname_size));
END IF;
id := id + 1;
IF (lastone) THEN
EXIT;
END IF;
x := y + 2;
END LOOP;
END;
/
-- =============================================
-- A mystery...
-- The property 'user.region=US' disappeared.
-- It was there yesterday!
-- Is it on your system? Today? Tomorrow?
-- =============================================
SELECT * FROM java_properties ORDER BY name;
SELECT * FROM java_properties WHERE value IS NULL ORDER BY name;
-- =============================================
-- Revoke java PropertyPermission...
-- =============================================
conn / as sysdba
CALL dbms_java.revoke_permission('UWCLASS', 'SYS:java.util.PropertyPermission', '*', 'read,write');
set linesize 121
col grantee format a10
col type_schema format a5
col type_name format a30
col name format a20
col action format a20
col enabled format a10
SELECT * FROM dba_java_policy
WHERE grantee = 'UWCLASS';
SELECT COUNT(*) FROM dba_java_policy;
SELECT * FROM dba_java_policy;
-- =============================================
-- Back to our user...
-- =============================================
conn uwclass/uwclass
set pagesize 30
set linesize 121
col name format a40
col value format a60
col id format 999
set serveroutput on
ALTER SESSION SET PLSQL_WARNINGS='ENABLE:ALL';
-- =============================================
-- The following should fail because of revoked permission...
-- =============================================
SELECT jp() FROM dual;
-- =============================================
-- But we still have our java_properties table...
-- =============================================
SELECT * FROM java_properties;
-- =============================================
-- Java & Oracle predefined permissions are described:
-- http://youngcow.net/doc/oracle10g/java.102/b14187/chnine.htm
-- ============================================= |
| |
| LOADJAVA |
Loads Java classes into the database
See: ?/rdbms/admin/initsjty.sql |
dbms_java.loadjava(option IN VARCHAR2) AS LANGUAGE JAVA NAME 'oracle.aurora.server.tools.loadjava.LoadJavaMain.serverMain(java.lang.String)'; |
| exec sys.dbms_java.loadjava('-v -r rdbms/jlib/sqljtype.jar'); |
| |
| REVOKE_PERMISSION |
| Disables any permissions that might have been granted |
dbms_java.revoke_permission(
grantee IN VARCHAR2,
permission_type IN VARCHAR2,
permission_name IN VARCHAR2,
permission_action IN VARCHAR2)
AS LANGUAGE JAVA NAME 'oracle.aurora.rdbms.security.PolicyTableManager.revoke(
java.lang.String, java.lang.String, java.lang.String, java.lang.String)'; |
| See GRANT_PERMISSION Demo Above |
| |
| SET_OUTPUT |
| Method for controlling destination of java output |
dbms_java.set_output(buffersize IN NUMBER); |
| exec dbms_java.set_output(1000000); |
| |
SET_RUNTIME_EXEC_CREDENTIALS  |
| Undocumented |
dbms_java.set_runtime_exec_credentials(
dbuser IN VARCHAR2,
osuser IN VARCHAR2,
ospass IN VARCHAR2); |
| TBD |
| |
| SHORTNAME |
| Returns the shorted class name |
dbms_java.shortname(longname IN VARCHAR2) RETURN VARCHAR2; |
SELECT dbms_java.shortname('oracle/mgd/idcode/IDCodeTranslator')
FROM dual; |