援引: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();
}
}
};
/