oracle如何使用java source调用外部程序
网络编程 2021-07-05 16:08www.168986.cn编程入门
这篇文章主要为大家介绍了oracle如何使用java source调用外部程序,感兴趣的小伙伴们可以参考一下
需求
Oracle调用第三方外部程序。Oracle使用sqluldr2快速导出大批量数据,然后用winrar压缩后发送邮件。
源码
java source
create or replace and pile java source named jv_run_extpro as import java.io.*; import java.lang.*; import java.util.*; import java.sql.*; import oracle.sql.*; publilass jv_run_extpro { publicstaticvoid 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"); errorGobbler.start(); outputGobbler.start(); try { p.waitFor(); } catch(InterruptedException ie) { System.out.println(ie); } } publicstatilass StreamGobbler extends Thread { InputStream is; String type; public StreamGobbler(InputStream is, String type) { this.is = is; this.type = type; } publicvoid run() { try { InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line = null; while ((line = br.readLine()) != null) { if (type.equals("Error")) { System.out.println("Error :" + line); } else { System.out.println("Debug:" + line); } } } catch (IOException ioe) { ioe.printStackTrace(); } } } }
存储过程
create or replace procedure pro_jv_run_extpro(p_cmd varchar2) as
language java name 'jv_run_extpro.run(java.lang.String)';
调用
begin pro_jv_run_extpro('sqluldr264.exe scott/hh@pdborcl query="select * from emp" field=, head=yes file=D:\Desk\tmp\sqluldr2\OUT2.TXT'); pro_jv_run_extpro('"D:\Program Files\WinRAR\Rar.exe" a -ep -df "D:\Desk\tmp\sqluldr2\20160916.rar" "D:\Desk\tmp\sqluldr2\OUT2.TXT"'); end;
总结
Java source里StreamGobbler这个类不能少,用于异步读取命令的输出。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程