ITPub博客

首页 > 数据库 > Oracle > Oracle Java Stored Procedure调用Unix shell

Oracle Java Stored Procedure调用Unix shell

Oracle 作者:哇哈哈8147 时间:2014-07-16 10:49:21 0 删除 编辑
援引:Doc ID 109095.1


首先,在数据库端创建调用Unix shell的java类,用Runtime.getRuntime().exec()实现


1.


CREATE OR REPLACE JAVA SOURCE NAMED "CaptureStream" as 
import java.util.*;
import java.io.*;


class CaptureStream implements Runnable {
    private final InputStream is;
    private final String type;
    private final OutputStream redirect;
    private boolean  redirected = false;




    CaptureStream(InputStream is, String type, OutputStream redirect)
    {
        this.is = is;
        this.type = type + ">";
        this.redirect = redirect;
    }


    CaptureStream(InputStream is, String type)
    {
        this(is, type, null);
    }




    CaptureStream(InputStream is)
    {
        this(is, " ", null);
    }


    public void run()
    {


        try {
            PrintWriter pw = null;
            if (redirect != null) {
                pw = new PrintWriter(redirect);
                redirected = true;
            }




            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String line=null;
            while ( (line = br.readLine()) != null) {
                System.out.println(type + line);    
                if (redirected) {
                    pw.println(line);
                }
            }
            if (redirected) {
                pw.flush();
                pw.close();
            }
            br.close();
            isr.close();
        } catch (IOException ioe) {
            ioe.printStackTrace();  
        }
    }
};
/

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29737239/viewspace-1220089/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-07-04

  • 博文量
    21
  • 访问量
    40460