日期:2014-05-17 浏览次数:20793 次
create or replace and compile java source named "shellcmd" as import java.io.*; import java.lang.*; public class shellcmd extends Object { public static int runcmd(String args) { Runtime rt = Runtime.getRuntime(); int RC = -1; try { Process p = rt.exec(args); int bufSize = 4096; BufferedInputStream bis =new BufferedInputStream(p.getInputStream(), bufSize); int len; byte buffer[] = new byte[bufSize]; while ((len = bis.read(buffer, 0, bufSize)) != -1) System.out.write(buffer, 0, len); RC = p.waitFor(); } catch (Exception e) { e.printStackTrace(); RC = -1; } finally { return RC; } } } create or replace procedure cmdshell(command in varchar2) as language java name 'shellcmd.runcmd(java.lang.String)'; exec dbms_java.grant_permission('SYSTEM','SYS:java.io.FilePermission','<<ALL FILES>>','execute'); -- 调用存储过程执行系统命令 set serveroutput on exec dbms_java.set_output(100000); exec cmdshell('...');