Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to read a properties file from a java stored procedure

321552Nov 5 2002
I tried running a java stored procedure that does not depend on any resource file, and it executed successfuly.
I am now trying to run a java stored procedure that reads information from a (.properties) file.
I combined both my java source file(ServletProperties.java) and the properties file (path.properties) into a zipped file (JavaSp.zip).
I then uploaded the zipped file using the loadjava command line utility.

c:>loadjava -u scott/tiger@s-server3:1521:portal -v -r -t JavaSp.zip

The loading was done successfully. I checked the user_objects table and the entries 'ServletProperties' and 'path.properties' where entered with a valid Status.
I created a callspec in the normal way and the package got created successfully and I was able to call it from SQL.

The code for the block responsible for reading the path.properties file is as follows:

Properties properties = new Properties();
try{
properties.load(new FileInputStream(path.properties));
}
catch (IOException){
System.out.println("file not found");
}

When I executed the procedure I got the error ORA-29532, telling me that relative path names are not allowed.

I read about that on the available documentation, and it mentioned that the full path name should be specified in the format '/fullpathname/filename'

So I changed the loading line to
properties.load(new FileInputStream(/path.properties));

and I also got the same error message


I also tried uploading the files on their own, by using
c:>loadjava -u scott/tiger@s-server3:1521:portal -v -r -t c:/path.properties
c:>loadjava -u scott/tiger@s-server3:1521:portal -v -r -t
c:/ServletProperties.java

The entry names in the user_objects table were 'ServletProperties' and 'c:/path.properties'

I also changed the loading line to
properties.load(new FileInputStream(c:/path.properties));

When I run the procedure, it run successfully, but an IOException was thrown indicating that the file was not found.

I read in the documentation that inorder to access the resource file, I had to grant a read/write permission, so I executed the following line
SQL> call dbms_java.grant_Permission('SCOTT', 'java.io.FilePermission','c:/path.properties','read,write');
SQL>commit;

and the command executed successfully ( I checked the entries in the USER_JAVA_POLICY table)

I need to know about how to load the files, knowing that both the java and properties files reside directly on the c:/ drive.
And how the java code responsible for loading the file should be written.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 4 2002
Added on Nov 5 2002
2 comments
1,213 views