How to open external files in a Java stored procedure?

Hi y'all,
I'm trying to open an external text file from a Java stored procedure. The java sp has been successfully loaded, resolved, published, etc. in Oracle. I'm using the following statement to try to open the file (enclosed in a try/catch block):
BufferedReader fileObj = new BufferedReader(new FileReader("fileName.txt"));
I'm getting a file not found error. Where is Oracle looking (i.e., what directory)?
Your help is greatly appreciated,
Gary

<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Gary Nool ([email protected]):
Hi y'all,
I'm trying to open an external text file from a Java stored procedure. The java sp has been successfully loaded, resolved, published, etc. in Oracle. I'm using the following statement to try to open the file (enclosed in a try/catch block):
BufferedReader fileObj = new BufferedReader(new FileReader("fileName.txt"));
I'm getting a file not found error. Where is Oracle looking (i.e., what directory)?
Your help is greatly appreciated,
Gary<HR></BLOCKQUOTE>
Hi Gary,
you must use a "database directory", e.g:
SQL>create directory WORKING_DIR as '/home2/common/';
SQL> select * from all_directories;
OWNER DIRECTORY_NAME
DIRECTORY_PATH
SYS WORKING_DIR
/home2/common/
Gert

Similar Messages

  • How to use signed classes/Jars in Java Stored Procedure?

    I am using java encryption API in my java application that I want to deploy as java stored procedure. The API is kept in the signed jar files.
    The Application is running in the MS-DOS environment but not in Oracle8i.
    It gives me following error.
    java.lang.ExceptionInInitializerError: java.lang.SecurityException: Cannot set
    up certs for trusted CAs
    at javax.crypto.b.<clinit>([DashoPro-V1.2-120198])
    at javax.crypto.KeyGenerator.getInstance([DashoPro-V1.2-120198])
    at DesKey.GenerateKey(DesKey.java:63)
    declare
    ERROR at line 1:
    ORA-29532: Java call terminated by uncaught Java exception:
    java.lang.ExceptionInInitializerError
    ORA-06512: at line 4
    (Note: I have enabled the java output in SQL Plus editor otherwise it will give only the second part of error that starts from ERROR at line 1:)
    please guide me how to solve this problem.
    Salman Hameed

    Salman,
    If you do not get a reply on this forum, I recommend you post this question on the Oracle JVM discussion forum as well.
    In addition, I would recommend checking the documentation for Oracle8i. The Oracle8i Java Developer's Guide, the Java Stored Procedures Guide, and the JDBC Developer's guide may have some information on this topic. You can get to this doc from the OTN Documentation page. Click on Oracle8i, then General Documentation, Release 2 (8.1.6), then scroll down to see the link for the Oracle8i Java Developer's documetation. All of the books mentioned above are available from that link.

  • ORA-29532 when trying to write to a file using a Java stored procedure

    I have a Java stored procedure which gives me the following error when I run it:-
    SQL> exec zipfile('c:\temp\test.txt');
    BEGIN zipfile('c:\temp\test.txt'); END;
    ERROR at line 1:
    ORA-29532: Java call terminated by uncaught Java exception:
    java.security.AccessControlException: the Permission (java.io.FilePermission
    c:\temp\test.txt.zip write) has not been granted to SCOTT. The PL/SQL to grant
    this is dbms_java.grant_permission( 'SCOTT', 'SYS:java.io.FilePermission',
    'c:\temp\test.txt.zip', 'write' )
    ORA-06512: at "SCOTT.ZIPFILE", line 1
    ORA-06512: at line 1
    I have tried running the dbms_java command as recommended as sys and have performed the necessary commit afterwards, also I have ran dbms_java.grant_permission( 'SCOTT', 'java.io.FilePermission',
    '*', 'write' )
    But I still get the ORA-29532.
    Does anyone have any ideas as to how I can get around this ?

    Are you getting ORA-29532 for the same file and the same permission ?
    Edited by: user769997 on Nov 23, 2009 12:57 AM

  • How to deploy signed jars/classes in Java Stored Procedure

    I am using java encryption API in my java application that I want to deploy as java stored procedure. The API is kept in the signed jar files.
    The Application is running in the MS-DOS environment but not in Oracle8i.
    It gives me following error.
    java.lang.ExceptionInInitializerError: java.lang.SecurityException: Cannot set
    up certs for trusted CAs
    at javax.crypto.b.<clinit>([DashoPro-V1.2-120198])
    at javax.crypto.KeyGenerator.getInstance([DashoPro-V1.2-120198])
    at DesKey.GenerateKey(DesKey.java:63)
    declare
    ERROR at line 1:
    ORA-29532: Java call terminated by uncaught Java exception:
    java.lang.ExceptionInInitializerError
    ORA-06512: at line 4
    (Note: I have enabled the java output in SQL Plus editor otherwise it will give only the second part of error that starts from ERROR at line 1:)
    please guide me how to solve this problem.
    Salman Hameed
    null

    Salman,
    If you do not get a reply on this forum, I recommend you post this question on the Oracle JVM discussion forum as well.
    In addition, I would recommend checking the documentation for Oracle8i. The Oracle8i Java Developer's Guide, the Java Stored Procedures Guide, and the JDBC Developer's guide may have some information on this topic. You can get to this doc from the OTN Documentation page. Click on Oracle8i, then General Documentation, Release 2 (8.1.6), then scroll down to see the link for the Oracle8i Java Developer's documetation. All of the books mentioned above are available from that link.

  • How to write call specs for a java stored procedure that takes a nested obj

    Example Class :
    public class B {
    int number;
    String str;
    public class A {
    private B[] _childern;
    public B[] getChildern(){
    return _children
    public static void saveAll(A a) throws SQLException {
    B[] children = a.getChildern();
    for(int i=0; i<children.length; i++){
    saveChild(children);
    public static void saveChild(B ch)throws SQLException {
    // do something
    What would be the call specification for the method A.saveAll(A)? Your help will be apprecited.
    Thank you
    Ajmal

    In other words, How to pass a Java Object from a Java stored procedure to a Java client ???
    Hello,
    I don't know to deal with a Vector object that has been generated from a stored procedure.
    Should I create first in the JDBC client and pass it as argument to the procedure ?
    Thanks in advance. Here is an extract ...
    On the client side :
    <<
    Vector buffer = new Vector();
    CallableStatement call =
    con.prepareCall ("{call my_procedure_run (?, ?)}");
    call.registerOutParameter(2, java.sql.Types.JAVA_OBJECT );
    call.setString (1, "bla bla bla");
    call.setObject (2, buffer);
    call.execute ();
    buffer = (Vector)call.getObject (2);
    >On the Java stored procedure
    <<
    public class my_procedure
    public static void Run(String input_value, Vector buffer)
    // ??? Vector buffer = new Vector();
    try
    while ( true )
    buffer.addElement(...) ;
    catch(Exception ex) { }

  • How to output various file types from a stored procedure

    Good morning, I would like to output to spreadsheet files like microsoft Excel, Lotus 123 or to a comma delimited text file from stored procedures. We run Oracle 8i and this report is accessed from an intranet site using stored procedures and the pl/sql web toolkit. The results would be more usefull in a spreadsheet format than web page(s). Can anyone give me a hint as to which process to follow to get the output. Thanks very much, Francois

    Probably best to try the PL/SQL SQL forum:
    http://forums.oracle.com/forums/forum.jsp?id=478021
    Some quick and easy pointers:
    * Take a look at the COM feature available from PL/SQL in 8i:
    http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/win.920/a95499/toc.htm
    * Just write the file out as comma delimited using UTL_FILE and give it a file name of .csv. Quick scan on google gives this example:
    http://www.flash.net/~swilliam/PLunloadSQL.txt
    Mike.

  • Loading jar files and calling java stored procedure

    I am trying to load jai_core.jar, jai_codec.jar, mlibwrapper.jar and another class I created into my project schema. I am having problems with resolving all of the class using the "loadjava -resolve" command as well as using the "alter java class" command. The single class I authored is not in a valid state as well as the PL/SQL wrapper for the function I am calling.
    My questions are:
    1) Does the single class need to be in a valid state before the PL/SQL wrapper will compile and be in a valid state itself?
    2) Are there any special tricks to this becuase the code I am using below doesn't seem to be working correctly?
    3. Should I worry about "resolving/validating" all of the class from the jar file? I have read conflicting views on this topic.
    SQL> CREATE OR REPLACE FUNCTION get_image (p_fileName in varchar2, p_offset in number )
    2 RETURN blob AS LANGUAGE Java
    3 NAME 'gov.irs.rtr.image.ImageUtilityFunction.getImage (java.lang.String, int) RETURN oracle.sql.BLOB';
    4 /
    Warning: Function created with compilation errors.
    SQL> show err
    Errors for FUNCTION GET_IMAGE:
    LINE/COL ERROR
    0/0 PL/SQL: Compilation unit analysis terminated
    3/1 PLS-00311: the declaration of
    "gov.irs.rtr.image.ImageUtilityFunction.getImage
    (java.lang.String, int) RETURN oracle.sql.BLOB" is incomplete or
    malformed
    Any help would be greatly appreciated.
    Regards,
    Joey

    We are using Oracle 9.2.0.8 and I have written the single class in 1.3.1.
    The first loadjava commands I tried were:
    loadjava -user username/password -resolve -resolver '((* RTRPROD)(* PUBLIC))' jai_core.jar jai_codec.jar mlibwrapper_jai.jar
    loadjava loadjava -user username/password -resolve -resolver '((* RTRPROD)(* PUBLIC) (* -))' ImageUtility.class
    Then I tried:
    loadjava -user username/password -resolve -resolver '((* RTRPROD)(* PUBLIC) (* -))' jai_core.jar jai_codec.jar mlibwrapper_jai.jar
    errors : class javax/media/jai/operator/EncodeDescriptor
    ORA-29534: referenced object RTRPROD.com/sun/media/jai/codec/ImageCodec could not be resolved
    errors : class javax/media/jai/operator/FileStoreDescriptor
    ORA-29534: referenced object RTRPROD.com/sun/media/jai/codec/ImageCodec could not be resolved
    errors : class com/sun/media/jai/opimage/BMPRIF
    ORA-29534: referenced object RTRPROD.com/sun/media/jai/opimage/CodecRIFUtil could not be resolved
    errors : class com/sun/media/jai/opimage/CodecRIFUtil
    ORA-29534: referenced object RTRPROD.com/sun/media/jai/codec/ImageCodec could not be resolved
    errors : class com/sun/media/jai/opimage/EncodeRIF
    ORA-29534: referenced object RTRPROD.com/sun/media/jai/codec/ImageCodec could not be resolved
    errors : class com/sun/media/jai/opimage/FPXRIF
    ORA-29534: referenced object RTRPROD.com/sun/media/jai/opimage/CodecRIFUtil could not be resolved
    errors : class com/sun/media/jai/opimage/GIFRIF
    ORA-29534: referenced object RTRPROD.com/sun/media/jai/opimage/CodecRIFUtil could not be resolved
    errors : class com/sun/media/jai/opimage/IIPCRIF
    ORA-29534: referenced object RTRPROD.com/sun/media/jai/codec/ImageCodec could not be resolved
    This error messages goes on and on for 44 files.
    I have found out that JAI is part of the Oracle 9 Release 2 but is part of the InterMedia package that is not installed. I would imagine that the JAI libraries mentioned above would be included in InterMedai. However, there are several dependencies on packages distributed in the Sun JDK but not the Oracle Runtime.
    Regards,
    Joey

  • Open external files

    I`ve been doing some research for a while, but haven`t found any solution for opening external files in my java app.
    Short about my problem:
    I`m giving users of the program the opportuninty to upload different kind of files. When a file is uploaded a label with the filename appears in the screen. When they click on the label I want my program to launch the correct program... Acrobat Reader for .PDF, Paint for jpg,gif.... aso.
    I found something similar that launch the cmd.exe, but it isn`t a general solution that opens all kinds of files...
    http://forum.java.sun.com/thread.jspa?threadID=625707&messageID=3569795
    As mentioned above I haven`t, so far, found a reliable solution for the problem, and I would have apprecated any kind of help.
    YS.
    Kaare

    Pre 1.6:
    JDIC
    org.jdesktop.jdic.desktop.Desktop.open(java.io.File)
    Java 6
    java.awt.Desktop.open(java.io.File)

  • Accessing files from Java Stored Procedures

    I am trying to access a file from a Java Stored Procedure but get the exception: "no such file or directory". The path and filename as seen by the database JVM is "\\wgcaub01\a1500is\fabi\mmv\mmvtestdata.txt".
    I have granted permissions to open the file using:
    call dbms_java.grant_permission('MMV', 'java.io.FilePermission', '\\\\wgcaub01\\a1500is\\fabi\\mmv\\mmvtestdata.txt', 'read');
    a) When I run the program as a Java class using a main method it works so the problem has to do with the Oracle JVM not finding the file.
    b) The MMV user has permissions on the file after granting them using the above dbms_java.grant_permission command.
    Can you tell me what am I missing? Is this a database configuration issue? Is there a problem with using a UNC path?
    (I am using FileReader and BufferedReader.)

    Vincent,
    Not sure if this is the cause of your problem, but I had some Java code which read from/wrote to a file, and I needed to run the following (you can obviously change <<ALL FILES>> to something more restrictive):
    declare
    security_key number;
    begin
    dbms_java.grant_permission('DAN', 'java.io.FilePermission', '<<ALL FILES>>', 'read,write,execute,delete', security_key);
    dbms_java.grant_permission('DAN', 'java.lang.RuntimePermission', 'writeFileDescriptor', NULL, security_key);
    dbms_java.grant_permission('DAN', 'java.lang.RuntimePermission', 'readFileDescriptor', NULL, security_key);
    end;
    Note that the security_key won't be set if the grant didn't work.
    Hope this helps,
    -Dan
    http://www.compuware.com/products/numega/dbpartner/dbpordebug.htm
    Debug PL/SQL and Java in the Oracle Database

  • Transactional file output from a Java Stored Procedure invoked by trigger.

    I need to write information to a file from a Java Stored
    Procedure which is called from an insert trigger. This works OK
    except for the condition when a rollback is performed - the file
    is updated anyway.
    I need the Java Stored Procedure file output to be part of the
    transaction - performed on commit and skipped on rollback. Is
    there any way the Java Stored Procedure can be aware of the
    state of the transaction?

    i am Still facing the following problem:
    if i pass a parameter like :
    rm -f /test/menu.ksh
    then the required output is that the menu.ksh file gets deleted.
    but when i pass this command:
    ./test/menu.ksh
    It is supposed to execute the specified script but it does not.
    I have tried multiple things like giving chmod 777 rights to the following file and changing the command to /test/menu.ksh but nothing happens
    Can you kindly tell me what can the problem be. Is there any execution rights issue: i am executing these scripts from pl sql developer.
    You can find both the procedure and java method which is being called below
    ==========================================================================================
    create or replace procedure TEST_DISPLAY(filename in varchar2, result out varchar2, error out varchar2) is
    command varchar2(100);
    vRetChar varchar2(100);
    begin
    command := filename ;
    prc_host(command, vRetChar);
    result := vRetChar;
    dbms_output.put_line(result);
    Exception
    when No_Data_Found Then
    error := 'Command is not Found';
    dbms_output.put_line('Failure');
    return;
    end TEST_DISPLAY;
    ======================================================================
    create or replace and compile java source named host as
    import java.io.*;
    import java.lang.Runtime;
    import java.lang.Process;
    import java.io.IOException;
    import java.lang.InterruptedException;
    public class Host {
    public static void executeCommand(String command,String[] outString) {
    String RetVal;
    try {
    String[] finalCommand;
    final Process pr = Runtime.getRuntime().exec(command);
    // Capture output from STDERR...
    }

  • View Java Stored Procedures

    Hello,
    How can I find the names of Java stored procedures
    created in the database and what are the published
    stored procedures?
    thanks
    Ranganath Samudrala

    Hi,
    There are two meta catalogs "okJavaObj" and "okJavaMember" that can be used to get all sorts of information for Java classes and Java methods. Some SQL commands are as follows:
    To see all Java classes stored in the database, type in the following select statement:
    select "Schema", "Name" from "okJavaObj" ;
    or you may want to create the following view:
    drop public synonym all_javaobjects;
    create or replace view all_javaobjects( Schema, Name, SuperClass, Type) as
    (select "Schema", "Name", "SuperClass", "Type" from "okJavaObj");
    grant select on all_javaobjects to public;
    create public synonym all_javaobjects for system.all_javaobjects;
    commit;
    You may want to create the following view to see classnames and methods
    drop public synonym all_methods;
    create or replace view all_methods
    (schema,classname, superclass, declaringclass, method_name, type, argcount, jnisignature) as
    select a."Schema", a."Name" as ClassName, a."SuperClass",
    b."DeclaringClass" , b."Name" as method_name , b."Type",
    b."ArgCount", b."JNISign" as jnisignature
    from "okJavaObj" a, "okJavaMember" b
    where a.POL_REF = b."DefinedIn";
    grant select on all_methods to public;
    create public synonym all_methods for system.all_methods;
    commit;

  • CLASSPATH configuration for jsp (java stored procedures)

    Hi.
    I have a very simple question for you people.
    I don't know where to set up the CLASSPATH configuration on a HP-UX so that Aurora can see this include jar file and my java stored procedure can run correctly.
    Thanks a lot.
    Flavio Matiello

    The way global variables could be created using java classes is by using static variables.The class variable values are stored in the JVM's memory
    In Oracle8i Each session gets its own JVM & hence you cannot have a Java class variable which could
    span across sessions.
    Hope this helps

  • How to call external files from java?

    How to call external files in java. For example how to call a *.pdf file to open in its default editor(say Acrobat), or a *.html file to open in the default browser or a *.txt file in a notepad etc..,
    In my program i have *.chm (Compiled Windows HTML Help) help file. how to open it in its default editor it?

    Jayarathina_Madharasan wrote:
    no one answered my questionHi what wrong did i do...basically insulted all the volunteers here who took the time to consider your question and try to offer you help. Other than that, you did nothing wrong.
    From JavaRanch :
    And even if an answer doesn't solve your problem, even if it should totally miss the point - the best thing to do to motivate others to continue trying to help you is showing respect and gratitude for the investment of time that was put into dealing with your issue.
    Edited by: Encephalopathic on Apr 14, 2008 10:01 AM

  • How to open/read file using Java in Unix?

    Hi Friends,
    Can you please help me out how to open/read file using java in unix os? I have create one text file in "/home/test.txt" in unix environment. How to open the same file & read using java code?
    - Hiren Modi

    http://java.sun.com/docs/books/tutorial/essential/io/index.html

  • Open a file into a java app - HOW DO YOU DO IT!!

    I have written an html/php editor - I want to set it up so that when you double click on a php file in windows it will open the file into my java ide.
    I know this can be done - but how!!! There does not seem to be any info on the web about it - can anyone give me some pointers.
    Thanks

    Yeah - but the problem is: You can only set files to
    open with a .exe file - if you go to the settings and
    set the .php file to "open with" you have to select a
    .exe file e.g. notepad.exe
    However you can't create .exe files in java!!!! So how
    do you do it?You have to spend $$$'s
    However many /most converters don't work without the relevant updated JVM (but they are *.exe, kind of)

Maybe you are looking for

  • How do you manage multiple Instances of an adjustment

    I'm trying very hard to learn Aperture but, one thing that I can't seem to figure out is how to manage multiple instances of the same adjustment. As an example, I create a new exposure adjustment to brush in exposure on the subjects teeth and then a

  • Offline but I'm not!

    I've searched the forums but everyone seems to have opposite problems.  Skype on my MacBook Air OSX version 10.9.5 running latest Skype 7.6 (409) will NOT allow me to change status from offline to online.  I've rebooted, I've reinstalled the latest S

  • Will App World ever stop being broken?

    Since I received my Playbook, I've attempted to make a purchase via App World on two separate occasions with two different credit cards only to be met with an authorization error each time. Apparently "authorization error" means RIM or Digital River

  • Problems with building web services - tutorial doesn't work

    I've been going through this tutorial from technet.oracle.com - trying to deploy the example stateless session bean service. First problem comes when running the deploy command - java -jar <j2ee_home>/admin.jar ormi://<host> <uid> <pwd> -deploy -file

  • Scroll bars keep disappearing

    I find that after using Safari for several minutes, the scroll bar on the side (which allows me to move the screen shot up or down to see more of a web page) will disappear. I have to close and reopen Safari in order to get the scroll bar back. What