日期:2014-05-17  浏览次数:20799 次

linux oracle 下 存储过程调用java执行系统命令失败
create or replace and compile java source named runcmd as
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class RunCmd
{
    private static void copyStream(InputStream inputStream, OutputStream outStream) throws IOException {
        byte[] bytes = new byte[1024];
        int size;
        while (inputStream.read(bytes) != -1) {
            outStream.write(bytes);
        }
    }
    public static void exec(String cmd){
     try {
             Process pc = Runtime.getRuntime().exec(cmd);
            copyStream(pc.getInputStream(), System.out);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
};


create or replace PROCEDURE SP_RUNCMD 
(cmd string) 
as language java name 'RunCmd.exec(java.lang.String)';


数据库是 oracle 11g
SP_RUNCMD 
这个存储过程,编译在windows下的oracle数据库中,
执行 exe SP_RUNCMD('cmd.exe /c echo 111>d:/ooxx.log');
成功生成 d:/ooxx.log文件

但是 这个存储过程,编译在linux(rhel 6.2 x64)下的oracle数据库中,
执行 exe SP_RUNCMD('sh /u01/start01.sh');
/u01/start01.sh文件的内容为
echo 111>/u01/20121111.log

但是,执行这个存储过程之后,没有生成/u01/20121111.log

------解决方案--------------------
不懂啊,帮顶..
我的异常网推荐解决方案:oracle存储过程,http://www.aiyiweb.com/oracle-develop/177537.html