• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Java stored procedure, cannot write file

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello I just want to implement a few Java stored procedures on Oracle 8.1.7 on Solaris. I would like to do:
exec FILE_OPEN -- opens /foo/bar/log for write
exec FILE_CLOSE -- closes
exec FILE_LOG 'h' -- writes 'h' to that file
I wrote the classes and loaded it to the server. I granted File permission on that file to read,write using dbms_java... However when I try to use these procedures I would get an IOException at FileOutputStream.writeChars(). The IOException has no other explanation so I am at a loss. I can actually open the file OK but when I write I get this exception. Any ideas on what may be wrong?
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the code inside might be more important to determine your problem. I think it is more of a Java problem than Oracle. I am going to move this to Java IO forum.
But Did you say how you are opening the File, you might be opening it as read-only, instead of read-write.
Here's an example using the RandomAccessFile class. f is a File class of the file on the file system.

Mark
 
Lei Sun
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No my Java code is OK.
At lease it is OK outside of Oracle.
Here it is:
I see the stuff being printed out on the SQL*Plus prompt after I turn on serveroutput etc. But nothing every appears in that file.
private static Writer logWriter;
static {
System.out.println("in init block");
try {
logWriter = new FileWriter("/usr/oracle/java/log");
logWriter.write("dsalkjssfd;lk");
logWriter.flush();
logWriter.close();
System.out.println("ok");
} catch (IOException iox) {
iox.printStackTrace(System.out);
System.out.println("not ok");
}
System.out.println("end of init block");
}
 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If u could move to Oracle9i, and using java stored procedure is not mandatory, u could use UTL_FILE supplied package to handle file I/O.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The UTIL_FILE Package exists prior to 9i I use it quite frequently with 8.1.5 and 8.1.7. If you are seeing your results via the SQL*PLUS buffer then my recommendation would be to contact you DBA and ask him to trouble shoot w/ you. We experienced a similiar problem while running the java application on the local machine and requesting the file to be created on a remote machine that the database exists on. It was due to a security issue.
On the server side the file to which the package can write to is driven by the entries in the init.ora file.
I do know if you are trying to output to a binary file prior to 9i you cannot accomplish this through the UTIL_FILE package.
 
reply
    Bookmark Topic Watch Topic
  • New Topic