How Oracle uses Java source to invoke external programs _oracle

Source: Internet
Author: User

Demand

Oracle invokes third party external programs. Oracle uses SQLULDR2 to quickly export large amounts of data and then send messages with WinRAR compression.

Source

Java source

Create or replace and compile Java source named Jv_run_extpro as import java.io.*; 
Import java.lang.*; 
Import java.util.*; 
Import java.sql.*; 
Import oracle.sql.*; Publicclass 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); 
} publicstaticclass Streamgobbler extends Thread {InputStream is; 


String type; 
Public Streamgobbler (InputStream are, 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); 

A catch (IOException IoE) {ioe.printstacktrace (); 

 

 } 

} 

} 

}

Stored Procedures

Create or Replace procedure Pro_jv_run_extpro (P_cmd varchar2) as

Language Java name ' Jv_run_extpro.run (java.lang.String) ';

Call

Begin 

Pro_jv_run_extpro (' Sqluldr264.exe scott/hh@pdborcl query= "SELECT * from emp" field=, Head=yes file=d:\ Desktop\tmp\sqluldr2\out2. TXT '); 
Pro_jv_run_extpro (' "D:\Program files\winrar\rar.exe" a-ep-df "D:\Desktop\tmp\sqluldr2\20160916.rar" "D:\Desktop\ Tmp\sqluldr2\out2. TXT "');
 
End 

Summarize

Java Source Streamgobbler This class cannot be used to read the output of commands asynchronously.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.