当前位置: 代码迷 >> Oracle开发 >> linux oracle 上 存储过程调用java执行系统命令失败
  详细解决方案

linux oracle 上 存储过程调用java执行系统命令失败

热度:632   发布时间:2016-04-24 07:09:21.0
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.daimami.com/search?q=177537
  相关解决方案