Kendi kodumdan Stored Procedure çağrısı yaparak aslında bir Java kodunu çalıştırmak mümkün.
Örnek
Şöyle yaparız
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED MYSCHEMA.JavaToolsASpackage util.oracle;import java.io.*;import java.net.InetAddress;import java.util.List;public class JavaTools {public static double pingOSCommand(String Command){double time = -1;try {Process process = Runtime.getRuntime().exec(Command);process.waitFor();BufferedReader stdInput = new BufferedReader( new InputStreamReader(process.getInputStream()));BufferedReader stdError = new BufferedReader( new InputStreamReader(process.getErrorStream()));while ((String s = stdInput.readLine()) != null) {if (s.contains("time=")) {if (s.contains("ms")){time = Double.parseDouble(s.substring(s.indexOf("time=")+5, s.indexOf("ms")-1));}}}while ((s = stdError.readLine()) != null) {System.out.println(s);}return time;} catch (Exception e){System.out.println(e.getMessage());return -1;}}};//******************************************************************************/GRANT EXECUTE ON JAVA SOURCE MYSCHEMA.RailwayJavaTools TO MYUSER;COMMIT;Execute dbms_java.grant_permission( 'MYUSER', 'SYS:java.io.FilePermission', '<<ALL FILES>>', 'execute');execute dbms_java.grant_permission( 'MYUSER', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '*' );execute dbms_java.grant_permission( 'MYUSER', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '*' );COMMIT;
Bunu çağırmak için şöyle yaparız. Sonuç olarak double döndürür
CREATE OR REPLACE PACKAGE MYSCHEMA.MyTools AS function f_pingOSCommand(command varchar2) return number; END MyTools; / CREATE OR REPLACE PACKAGE body MYSCHEMA.MyTools AS function f_pingOSCommand(command varchar2) return number as language java NAME 'util.oracle.JavaTools.pingOSCommand(java.lang.String) return double'; end MYTools; /
Bunu çağırmak için şöyle yaparız. Sonuç olarak double döndürür
SELECT MYSCHEMA.MyTools.f_pingOSCommand(?) FROM DUAL
Hiç yorum yok:
Yorum Gönder