想用存储过程调用一个外部exe,比方说c盘下的notepad.exe文件,参考了一些大虾的做法,如下:
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED RunDx AS
import java.io.*;                                                               
public class RunDx{                                                         
  public static String Run(){                                     
     try{                 
System.out.println("success");
Runtime.getRuntime().exec("C:"); 
Runtime.getRuntime().exec("notepad.exe");       
        return("0");                                                                  
     }                                                                          
     catch (Exception e){                                                       
        System.out.println("Error running command:" + e.getMessage());    
        return(e.getMessage());  
     }                                                                          
  }                                                                             
}
/create or replace procedure RunDx  
as language java  
name 'RunDx.Run()';
/
set serveroutput on size 5000
call dbms_java.set_output(5000);
exec RunDx ;
编译没问题,但是在执行的时候出现Error running command:the Permission (java.io.FilePermission <<ALL FILES>>
execute) has not been granted to TTT. The PL/SQL to grant this is
dbms_java.grant_permission( 'TTT', 'SYS:java.io.FilePermission', '<<ALL
FILES>>', 'execute' )按照提示执行
EXEC SYS.dbms_java.grant_permission( 'TTT', 'SYS:java.io.FilePermission', '<<ALLFILES>>', 'execute' )
后,问题依然出现,求助高手,该怎么解决

解决方案 »

  1.   

    用户或procedure有没有执行的权限?
      

  2.   

    执行EXEC SYS.dbms_java.grant_permission( 'TTT', 'SYS:java.io.FilePermission', '<<ALLFILES>>', 'execute' )有没有题是错误?
      

  3.   

    java.io.FilePermission  --看起来好像是找不到文件...听楼上的吧.
      

  4.   

    试试使用C语言开发一个DLL怎么样?1. 以数据库管理员权限登录,建立必要的用户名(暂定为cdx)和全局同义名:create user cdx identified by "123";
    grant connect to cdx;
    grant create library to cdx;
    grant create procedure to cdx;
    create public synonym cdxpack for cdx.cdxpack;alter user cdx default tablespace users temporary tablespace temp;
    alter user cdx quota unlimited on users;
    2. 建立必要的日志表纪录(根据需要,这一步也可以不要)用于当向表中增加纪录时,
    调用触发器进行根据合法性检查,根据结果(是否为真)判断是否调用外部命令。
    create table cdx.cmdrunlog 
    (
    usr_name varchar2(50),
    run_date date,
    cmd_str varchar2(50),
    para_str varchar2(50),
    run_rtecode number(10)
    );
    /
    3. 编辑文件extproc.c,保存在:e:\extproc目录#include <stdio.h>
    #include <stdlib.h>
    #include <time.h>int RunSysCmd(char * str,char * parastr)
    {
    char CmdStr[300];if ( str == NULL )
    return 1;
    if (parastr != NULL)
    sprintf(CmdStr,"%s %s",str,parastr);
    else
    sprintf(CmdStr,"%s",str);
    return system(CmdStr);
    }3. 运行命令 cl -I. /LD -Zi extproc.c /link msvcrt.lib /nod:libcmt /DLL
    生成动态库文件extproc.dll,注意它的存放路径。
    4. 运行命令
    sqlplus cdx/123
    登陆后,输入如下脚本,创建自定义的进程库:
    CREATE OR REPLACE LIBRARY cdxlib IS 'e:\extproc\extproc.dll';
    /
    show errors;CREATE OR REPLACE PACKAGE cdxpack IS 
    FUNCTION RunSysCmd(str IN CHAR,parastr IN CHAR) RETURN BINARY_INTEGER;
    end cdxpack;
    /
    show errors;CREATE OR REPLACE PACKAGE BODY cdxpack IS
    FUNCTION RunSysCmd(str IN CHAR,parastr IN CHAR) 
    RETURN BINARY_INTEGER
    IS EXTERNAL
    NAME "RunSysCmd"
    LIBRARY cdxlib
    PARAMETERS (
    str BY REFERENCE,
    parastr BY REFERENCE);
    end cdxpack;
    /
    show errors;5. 编辑一个文本文件测试上面操作的正确性,文件名为testpack.sql:declare
    str1 CHAR(50) :='dir';
    parastr1 char(50) :='e:\ >e:\extproc\pack.txt';
    nRetVal binary_integer;
    begin
    nRetVal := cdxpack.RunSysCmd(str1,parastr1);
    dbms_output.put_line('cdxpack.RunSysCmd:'|| nRetVal);
    end;
    /exit;
    /
      

  5.   

    需要修改 listerer.ora
    其中
    (ENVS="EXTPROC_DLLS=ANY")
    是需要增加的行
    *************************************
    LISTENER =
      (DESCRIPTION_LIST =
        (DESCRIPTION =
          (ADDRESS_LIST =
            (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC))
          )
          (ADDRESS_LIST =
            (ADDRESS = (PROTOCOL = TCP)(HOST = zhddsrv)(PORT = 1521))
          )
        )
      )SID_LIST_LISTENER =
      (SID_LIST =
        (SID_DESC =
          (SID_NAME = PLSExtProc)
          (ORACLE_HOME = /export/home/oracle/u01/app/oracle/product)
          (PROGRAM = extproc)
          (ENVS="EXTPROC_DLLS=ANY")
        )
      )
      

  6.   

    这几天让别的工作耽误了,没顾及这个问题。谢谢 楼上各位的热心帮助,特别是yanran_hill(燕然)的解答,不过现在要求用java,不能采用c dll 。继续顶这个问题。
      

  7.   

    权限问题前几天解决了,但是怎么调用不了notepad.exe呢,存储过程只显示正常完成。
      

  8.   

    几天前把机器做了,模糊记得代码是这么写的
    REATE OR REPLACE AND COMPILE JAVA SOURCE NAMED RunDx AS
    import java.io.*;                                                               
    public class RunDx{                                                         
      public static String Run(){                                     
         try{                 
            System.out.println("success");
            Runtime.getRuntime().exec("CD C:\\"); 
            Runtime.getRuntime().exec("aa.bat");       
            return("0");                                                                  
         }                                                                          
         catch (Exception e){                                                       
            System.out.println("Error running command:" + e.getMessage());    
            return(e.getMessage());  
         }                                                                          
      }                                                                             
    }
    当时能够调用notepad,但是现在没有反应。
      

  9.   

    CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED RunDx AS
    import java.io.*;                                                               
    public class RunDx{                                                         
        public static String Run(){                                     
           try{                 
               Runtime runtime = Runtime.getRuntime();
               Process process = runtime.exec("cmd /c start  c:\\NOTEPAD.EXE");
               System.out.println("success");
               //Runtime.getRuntime().exec("C:"); 
               //Runtime.getRuntime().exec("notepad.exe");       
               return("0");                                                                  
               }                                                                          
         catch (Exception e){                                                       
               System.out.println("Error running command:" + e.getMessage());    
               return(e.getMessage());  
               }                                                                          
         }                                                                             
    }
    /
    还是不成。。