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 -> Re: Java Procedure Doesn't Exist When Executed

Re: Java Procedure Doesn't Exist When Executed

From: Michael O'Shea <michael.oshea_at_tessella.com>
Date: 13 Jun 2006 00:29:37 -0700
Message-ID: <1150183776.982091.54220@g10g2000cwb.googlegroups.com>


> Resant wrote:
> You mean the name must be case sensitive? I think is not. It's still
> doesn't work.
> Any other idea please?
>
> Thanks,
>
> Resant

Hi again Resant. Java class names are case sensitive. I have modified *your* code to demonstrate what it should look like/included inline below.

The error that occurs at the end of the script is a privilege issue. Oracle tells you in the error message what privs are necessary & how to grant them.
Regards
Mike

TESSELLA Michael.OShea_at_tessella.com

__/__/__/  Tessella Support Services plc
__/__/__/  3 Vineyard Chambers, ABINGDON, OX14 3PX, England
__/__/__/  Tel: (44)(0)1235-555511  Fax: (44)(0)1235-553301
www.tessella.com Registered in England No. 1466429

SQL>
SQL> CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Whatever" AS   2 import java.io.*;
  3 public class ExecCommand
  4 {
  5 public static int runCommand(String cmd) throws IOException   6 {

  7      Process proc = Runtime.getRuntime().exec(cmd);
  8      try
  9      {
 10        proc.waitFor();
 11      }
 12      catch (InterruptedException e)
 13      {
 14        System.err.println("process was interrupted");
 15        return -1;
 16      }
 17
 18      if (proc.exitValue() != 0)
 19      {
 20        System.err.println("exit value was non-zero");
 21        return -2;
 22      }
 23
 24      // return success
 25      return 0;

 26 }
 27 }
 28 /

Java created.

SQL>
SQL>
SQL> CREATE OR REPLACE FUNCTION EXEC_COMMAND(Command IN varchar2)
RETURN
  2 NUMBER AS LANGUAGE JAVA
  3 NAME 'ExecCommand.runCommand(java.lang.String) return int';   4 /

Function created.

SQL>
SQL> SELECT exec_command('dir') FROM DUAL;

                                *

ERROR at line 1:
ORA-29532: Java call terminated by uncaught Java exception: java.security.AccessControlException: the Permission (java.io.FilePermission
<<ALL FILES>> execute) has not been granted to SCOTT. The PL/SQL to grant this
is dbms_java.grant_permission( 'SCOTT', 'SYS:java.io.FilePermission', '<<ALL
FILES>>', 'execute' )

SQL> SELECT *
  2 FROM V$VERSION; BANNER



Oracle Database 10g Enterprise Edition Release 10.1.0.4.0 - Prod PL/SQL Release 10.1.0.4.0 - Production
CORE 10.1.0.4.0 Production
TNS for 32-bit Windows: Version 10.1.0.4.0 - Production NLSRTL Version 10.1.0.4.0 - Production
SQL>
SQL>
SQL>
Received on Tue Jun 13 2006 - 02:29:37 CDT

Original text of this message

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