Oracle calls external programs using Java source

Source: Internet
Author: User
Tags rar

Oracle Use Java source Calling external programs

Demand

Oracle calls third-party external programs. Oracle uses SQLULDR2 to quickly export large quantities of data and then use WinRAR to compress and send messages.

Original code

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 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 ();

}

}

}

}

?

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/[email protected] 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 is not small, for asynchronous read command output.

Oracle calls external programs using Java source

Related Article

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.