This post is about how to get the contents of a resource file that is loaded into Oracle as part of Java Stored Procedures package. I’ve recently posted about Java Stored Procedures in general here.
While working on enhancing some Java procedures, I added a simple Java logger class, fashioned after Log4J. To be able to dynamically configure the logging properties (log levels, threshold), I added in a properties file, bundled into the Jar file itself1. After loading the properties file into the Database (using LoadJava command; loaded as a Java Resource), I wanted a way to “see” what’s inside the file. That’s when I posted a question on StackOverflow, but eventually googled and found the answer. See my question and my own answer here. And here is the script, I came up with:
SET SERVEROUTPUT ON EXEC DBMS_JAVA.SET_OUTPUT (1000000); DECLARE bText CLOB; len PLS_INTEGER; offset PLS_INTEGER; text VARCHAR2(2000); BEGIN DBMS_LOB.CreateTemporary(bText, FALSE ); DBMS_JAVA.Export_Resource('LAJavaSP.properties', bText); len := 1000; -- length of the lob to read. offset := 1; DBMS_LOB.Read(bText, len, offset, text); DBMS_OUTPUT.Put_Line(text); END; /
This printed the following:
getSystemResourceAsStream.Otherwise, we will have to worry about Directory objects, Permissions etc.