2013年(350)
分类: Mysql/postgreSQL
2013-04-24 11:11:05
首先创建java sources并编译~~
create or replace and compile java source named stringutil as
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URLConnection;
import java.net.URL;
public class StringUtil
{
public static String getUrlString(String myUrl) {
String result = null;
InputStreamReader ISR = null;
BufferedReader in= null;
if (myUrl != null){
try{
URL url= new URL(myUrl); //得到文件的URL地址
ISR = new InputStreamReader(url.openStream(),"GB2312");
in = new BufferedReader(ISR);
String line;
StringBuffer content = new StringBuffer(); //文件内容
while ((line = in.readLine()) != null) { //读取文件
content.append(line+"n");
}
result = content.toString();
}
catch(Exception ex){
return "@err:"+ex.getMessage();
}
finally{
try{
if (in != null)in.reset();
}catch(Exception e){
}
try{
if (ISR != null)ISR.reset();
}catch(Exception e){
}
}
}
return result;
}
}
定义一个function
create or replace function Java_getUrlString(str In Varchar) return varchar2 as赋予当前用户执行权限
call dbms_java.grant_permission(username, 'SYS:java.net.SocketPermission','*', 'connect,resolve' );
最后测试看看是否有返回:
Select Java_getUrlString('') From dual;