创建java source
CREATE OR REPLACE and COMPILE JAVA SOURCE NAMED exesyscommand as
import java.io.*;
public class ExeSysCommand {
public static String ExeCmd(String cmd){
Process proc =null;
int exitVlue;
try{
System.out.println(cmd);
proc = Runtime.getRuntime().exec(cmd);
exitVlue = proc.waitFor();
if (exitVlue == 0){
return "PASS";
} else {
return "FAIL";
}
} catch (Exception e){
return e.getMessage();
}
}
public static void main(String[] args) {
System.out.println("--------------------------");
System.out.println(ExeCmd(args[0]));
System.out.println("--------------------------");
}
}
创建function调用javasource
CREATE OR REPLACE FUNCTION ExeCmd
(cmd string)
RETURN varchar2
IS
LANGUAGE JAVA NAME 'ExeSysCommand.ExeCmd(java.lang.String) return java.lang.String';
授权用户执行java的权限
exec dbms_java.grant_permission( 'JYCRMX', 'SYS:java.io.FilePermission', 'D:\01_import.bat', 'execute');
exec dbms_java.grant_permission( 'JYCRMX', 'SYS:java.io.FilePermission', '<>', 'execute');
来源:CSDN
作者:Weki.wang
链接:https://blog.csdn.net/Wek_Wang/article/details/103697903