如何在oracle的存储过程中调用server上的bat或exe文件

    技术2022-05-11  19

    1. 授于test用户文件读写和执行命令的权限

    SQL>exec dbms_java.grant_permission('TEST','SYS:java.io.FilePermission','<<ALL FILES>>','read,write,execute,delete');

     

    SQL>exec dbms_java.grant_permission('TEST','java.lang.RuntimePermission','*','writeFileDescriptor' );

     

    2. 建立java source

    CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "bb" as import java.io.*;import java.lang.*;import java.util.*;import java.sql.*;import oracle.sql.*;

    public class bb{public static void invoke_exe() throws IOException{Process p=Runtime.getRuntime().exec("d:/exp_74.bat");--注意/符号try{p.waitFor();}catch(InterruptedException ie){System.out.println(ie);}}}/

     

    3. 建立调用java source的存储过程CALL_BB

     

    create or replace procedure CALL_BBas   language java   name 'bb.invoke_exe()';/

     

    4. 执行CALL_BB即可;

     


    最新回复(0)