Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> OraJava function vs. procedure

OraJava function vs. procedure

From: Jesse, Rich <Rich.Jesse_at_qtiworld.com>
Date: Fri, 25 Jan 2002 11:26:26 -0800
Message-ID: <F001.003FB99B.20020125112008@fatcity.com>

So, there I am. 8.1.7.2 with JVM loaded in Oracle. I need to be able to access the Unix shell from within a procedure, so naturally, I plagiarize and modify a very simple Java class from somewhere in Metalink:

import java.lang.Runtime;
import java.lang.Process;
import java.io.IOException;
import java.lang.InterruptedException;

class QT_Exec_OS {

        public static int main(String args[]) {

        int retval = 0;

        try {
                String  ftpCommand;
                ftpCommand = "/usr/bin/ls " + args[0];

                Process p = Runtime.getRuntime().exec(ftpCommand);

                try {
                        p.waitFor();
                } catch (InterruptedException intexc) {
                retval = 700;
        }

        retval = p.exitValue();

        } catch (IOException e) {
                e.printStackTrace();
                retval = 701;
        }
        return retval;

   }
}

And then, the PL/SQL wrapper:

CREATE OR REPLACE PROCEDURE qt_rjtest (S1 IN VARCHAR2) AS LANGUAGE JAVA
name 'QT_Exec_OS.main(java.lang.String[])'; /

This works fine, but I'm not sure why. According to Metalink, I should be getting a PLS-311 error because the Java code is returning a value. Hmmmm. But when I try to create a PL/SQL function to make use of the Java code's return value:

CREATE OR REPLACE FUNCTION qt_rjtest_f (S1 IN VARCHAR2) RETURN NUMBER
AS LANGUAGE JAVA
name 'QT_Exec_OS.main(java.lang.String[]) return int'; /

...I get the PLS-311 "the declaration of "QT_Exec_OS.main(java.lang.String[]) return int" is incomplete or malformed" error.

So, I'm guessing that the Java doesn't actually return a value, but I can't figure out why.

Anyone?

TIA!

Rich Jesse                           System/Database Administrator
Rich.Jesse_at_qtiworld.com              Quad/Tech International, Sussex, WI USA

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Jesse, Rich
  INET: Rich.Jesse_at_qtiworld.com

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Fri Jan 25 2002 - 13:26:26 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US