06 July 2007

How to Find Java(JVM) Version of Oracle Programatically

SQL> create or replace and compile java source named java_version as
2 public class JavaVersion
3 {
4 public static String Get()
5 {
6 String Version = System.getProperties().getProperty("java.version");
7 return Version;
8 }
9 }
10 /
Java created
SQL>
SQL> CREATE OR REPLACE FUNCTION fnc_JavaVersion RETURN VARCHAR2 AS
2 LANGUAGE JAVA NAME 'JavaVersion.Get( ) return java.lang.String';
3 /
Function created
SQL> SELECT fnc_JavaVersion() FROM dual;
SELECT fnc_JavaVersion() FROM dual
ORA-29532: Java call terminated by uncaught Java exception: java.security.AccessControlException: the Permission (java.util.PropertyPermission * read,write) has not been granted to SYSADM. The PL/SQL to grant this is dbms_java.grant_permission( 'SYSADM', 'SYS:java.util.PropertyPermission', '*', 'read,write' )
SQL> exec dbms_java.grant_permission( 'SYSADM', 'SYS:java.util.PropertyPermission', '*', 'read,write' );
PL/SQL procedure successfully completed
SQL> SELECT fnc_JavaVersion() FROM dual;
FNC_JAVAVERSION()
--------------------------------------------------------------------------------
1.4.1
SQL>

No comments: