需求
Oracle调用第三方外部程序。Oracle使用sqluldr2快速导出大批量数据,然后用winrar压缩后发送邮件。
原码
授权
java source
create or replace and compile java source named jv_run_extpro as
public static void run(String cmd) throws IOException
Process p=Runtime.getRuntime().exec(cmd);
StreamGobbler errorGobbler = new StreamGobbler(p.getErrorStream(), "Error");
StreamGobbler outputGobbler = new StreamGobbler(p.getInputStream(), "Output");
catch(InterruptedException ie)
public static class StreamGobbler extends Thread {
public StreamGobbler(InputStream is, String type) {
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
while ((line = br.readLine()) != null) {
System.out.println("Error :" + line);
System.out.println("Debug:" + line);
StreamGobbler这个类不能少,用于异步读取命令的输出。
存储过程
create or replace procedure pro_jv_run_extpro(p_cmd varchar2) as
language java name 'jv_run_extpro.run(java.lang.String)';