Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Java Procedure Doesn't Exist When Executed
Resant wrote:
> I've add the permission by script :
>
> dbms_java.grant_permission( 'SCOTT', 'SYS:java.io.FilePermission',
> '<<ALL FILES>>', 'execute' )
>
> and try to select again, but get error :
> ERROR at line 1:
> ORA-29532: Java call terminated by uncaught Java exception:
> java.io.IOException: The handle is invalid.
>
> Something wrong with the Java procedure?
>
> Thanks
>
> Resant
To add to Michael's corrections... you should make an effort to learn some basics about java, built in java security mechanism and the OS where your Oracle database is running. Without this, you will be shooting in the dark. Goto http://java.sun.com and download java docs.
In the following simple example, I have three 0 byte files in c:\temp and I have granted execute on javasyspriv role to system.
C:\>dir /b c:\temp
file1.txt file2.txt file3.txt
C:\>sqlplus system
SQL*Plus: Release 9.2.0.7.0 - Production on Tue Jun 13 14:11:50 2006
Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
Enter password:
Connected to:
Oracle9i Enterprise Edition Release 9.2.0.7.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.7.0 - Production
SQL> create or replace and compile java source
2 named "TestIO"
3 as
4 import java.io.*;
5
6 public class TestIO {
7
8 public static void testio (String cmd) 9 throws Exception { 10 11 Runtime r = Runtime.getRuntime(); 12 Process p = r.exec(cmd); 13 14 BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); 15 String s; 16 while ((s = br.readLine()) != null) { 17 System.out.println(s); 18 } 19 br.close(); 20 p.waitFor(); 21 }
Java created.
SQL> create or replace procedure testio_wrapper (
2 cmd_ in varchar2 )
3 as
4 language java name 'TestIO.testio(java.lang.String)';
5 /
Procedure created.
SQL> set serverout on
SQL> exec dbms_java.set_output(20000);
PL/SQL procedure successfully completed.
SQL> exec testio_wrapper('cmd /c dir /b c:\temp');
file1.txt file2.txt file3.txt
PL/SQL procedure successfully completed.
SQL> exec testio_wrapper('cmd /c del c:\temp\file1.txt');
PL/SQL procedure successfully completed.
SQL> exec testio_wrapper('cmd /c dir /b c:\temp');
file2.txt
file3.txt
PL/SQL procedure successfully completed.
Regards
/Rauf
Received on Tue Jun 13 2006 - 09:19:11 CDT