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

Home -> Community -> Usenet -> c.d.o.server -> Java Procedure Doesn't Exist When Executed

Java Procedure Doesn't Exist When Executed

From: Resant <resant_v_at_yahoo.com>
Date: 12 Jun 2006 03:31:33 -0700
Message-ID: <1150108293.328079.104350@h76g2000cwa.googlegroups.com>


I try this below script and the procedure created successfully, but when I execute it from Oracle, it shows error :

class EXECCOMMAND does not exist

The code is :

DECLARE
  RetVal NUMBER;
BEGIN
  RetVal := TEST.EXEC_COMMAND('dir');
  dbms_output.put_line(RetVal);
END; Java Class:

import java.io.*;

public class ExecCommand
{
  public ExecCommand()
  {
  }

  static public int runCommand(String cmd) throws IOExcepti   {
    // start command running
    Process proc = Runtime.getRuntime().exec(cmd);

    // wait for command to terminate
    try
{

      proc.waitFor();
    }
    catch (InterruptedException e)
{

      System.err.println("process was interrupted");
      return -1;

    }

    // check its exit value
    if (proc.exitValue() != 0)
{

      System.err.println("exit value was non-zero");
      return -2;

    }

    // return success
    return 0;
  }

  public static void main(String args[]) throws IOException   {
    String cmdString = args[0];
    System.out.println("command string is: " + cmdString);

    try
{

      //run a command
      int retVal = runCommand(cmdString);

      System.out.println("return value is: " + retVal);
    }
    catch (IOException e)
{

      System.err.println(e);
    }
  }
}
/

Function :
CREATE OR REPLACE FUNCTION EXEC_COMMAND(Command IN varchar2) RETURN NUMBER AS
LANGUAGE JAVA
NAME 'EXECCOMMAND.runCommand(java.lang.String) return int'; /

Any wrong with the script?

Many thanks for any help given.

Resant Received on Mon Jun 12 2006 - 05:31:33 CDT

Original text of this message

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