1 Reply Latest reply on Jul 1, 2013 1:54 PM by mjungerm-Oracle

    Cannot read System property on Oracle JVM unless class is reloaded


      I want to be able to read system properties set with DBMS_JAVA.set_property from a java stored procedure. For this, I have this simple code:


      public static String getEnvironmentVar(String propertyName) {
              return System.getProperty(propertyName);


      When I run this on the database, the java stored procedure doesn't seem to load the property just set with DBMS_JAVA.set_property:


           s      varchar2(100);
           s := dbms_java.set_property('test_prop', 'test_val');
           s := getEnvironmentVar('test_prop');  -- This is my java stored proc


      However, once I reload the class into Oracle (with loadjava); the property is read correctly. Am I missing something ?



        • 1. Re: Cannot read System property on Oracle JVM unless class is reloaded

          If you try the declare in a new RDBMS session I believe you will find that it works.  Or insert the line


          s:= dbms_java.endsession;


          between the dbms_java.set_property and the getEnvironmentVar call.  When dbms_java.set_property is called, it establish a value for a property that is only used in subsequent initializations of the java VM during the current RDBMS session.  It does not affect the java VM that has already been initialized in the session, if any.  If java has not been used before in the current session, then the VM will be initialized when the getEnvironmentVar call is done and the value established earlier by dbms_java.set_property will be seen.  But if java had already been in use in the session, such as would happen if you had earlier created or resolved the class containing the method getEnvironmentVar in that session, then the value set by dbms_java.set_property will not be seen (unless and until something (like dbms_java.endsession, System.exit or some fatal error) occurs to terminate the existing java VM without terminating the RDBMS session).