http://overloving.iteye.com/blog/1587026
http://blog.sina.com.cn/s/blog_4ca246370101b309.html
参考上面的:
引用jar包 ganymed-ssh2-build210.jar
jar 包放在 $ORACLE_HOME/sqlj/lib 执行loadjava命令 加载jar包
路径下 执行 包加载
# 10gR2
loadjava -u sys/password -r -v -f -genmissing -s -grant public demo1.jar demo2.jar
# 11g
loadjava -u sys/password -r -v -f -genmissing -s -grant public demo1.jar demo2.jar
loadjava -u sys/password -r -v -f -genmissing -s -grant public jar包名字.jar
在oracle中创建java类
create or replace and compile java source name HelloWorld as
package test;import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.List;
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.ConnectionInfo;
import ch.ethz.ssh2.Session;
import ch.ethz.ssh2.StreamGobbler;
public class Linuxs {
public static String Pwd(String string1, String string2, String string3,
String string4){
Connection conn = null;
String line = new String();
try {
conn = new Connection(string1);
ConnectionInfo info = conn.connect();
boolean result = conn.authenticateWithPassword(string2, string3);
System.out.println(result);
Session session = conn.openSession();
session.execCommand("cd " + string4 + " && ls ");
InputStream stdout = new StreamGobbler(session.getStdout());
BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
List<String> list = new LinkedList<String>();
while (true) {
line = br.readLine();
if (line != null){
line = line+"|";
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
conn.close();
}
return line;
}
}
创建函数
string2 varchar2,string3 varchar2,string4 varchar2) RETURN VARCHAR2 as
LANGUAGE JAVA name 'Linuxs.Pwd(java.lang.String,java.lang.String,java.lang.String,java.lang.String) return java.lang.String';
创建后设置输出长度
SQL> set serveroutput on size 2000
SQL> call dbms_java.set_output(2000);
后面的调用我就不知道怎么调了。