本文共 1201 字,大约阅读时间需要 4 分钟。
今天测试了一段ORACLE SQL脚本,可以实现对Windows系统下的硬盘进行写文件操作。以下的测试图,并附脚本代码。
脚本代码:
create or replace and compile
java souRCe named "util" as import java.io.*; import java.lang.*; public class util extends Object { public static int RunThis(String args) { Runtime rt = Runtime.getRuntime(); int RC = -1; try { Process p = rt.exec(args); int bufSize = 4096; BufferedInputStream bis =new BufferedInputStream(p.getInputStream(), bufSize); int len; byte buffer[] = new byte[bufSize]; // Echo back what the program spit out while ((len = bis.read(buffer, 0, bufSize)) != -1)
System.out.write(buffer, 0, len); RC = p.waitFor(); } catch (Exception e) { e.printStackTrace(); RC = -1; } finally { return RC; } } } / create or replace function RUN_CMz(p_cmd in varchar2) return number as language java name 'util.RunThis(java.lang.String) return integer'; / create or replace procedure RC(p_cmd in varChar) as x number; begin x := RUN_CMz(p_cmd); end; / variable x number; set serveroutput on; exec dbms_java.set_output(100000); grant javasyspriv to system; grant javauserpriv to system; exec:x:=run_cmz('cmd.exe cmd/C dir c:\ >c:\windows\dir.bat'); exit本文转自enables 51CTO博客,原文链接:http://blog.51cto.com/niuzu/646186,如需转载请自行联系原作者