问题:
有一台windows 2003的ORACLE11G数据库服务器,可以连接数据库,但忘记了administartor的口令。由于硬盘都做了RAID,使用WINPE启动后,看不到C盘。网上的一种做法是使用支持RAID驱动的WINPE引导,但服务器时限久,已找不到RAID驱动。
思路:
使用ORACLE的JAVA存储过程执行操作系统的命令。
过程:
SQL> conn sys/oracle@hisserver as sysdba
Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
Connected
as SYS
SQL> create or replace and compile java source named oscmd as
2
import java.io.*;
3
import java.lang.*;
4
public class OSCmd extends Object {
5 public static int OSCmd(String args) {
6 Runtime rt = Runtime.getRuntime();
7 int rc = -1;
8 try {
9 Process p = rt.exec(args);
10 int bufSize = 4096;
11 BufferedInputStream bis = new BufferedInputStream(p.getInputStream(),
bufSize);
12 int len;
13 byte buffer[] = new byte[bufSize];
14 while ((len = bis.read(buffer, 0,
bufSize)) != -1)
15 System.out.write(buffer, 0,
len);
16 rc = p.waitFor();
17 } catch (Exception e) {
18 e.printStackTrace();
19 rc = -1;
20 } finally {
21 return rc;
22 }
23 }
24
}
25
/
Java created
SQL> CREATE OR REPLACE FUNCTION Run_Cmd(p_Cmd IN VARCHAR2) RETURN
NUMBER
2
AS LANGUAGE JAVA NAME
3
'OSCmd.OSCmd(java.lang.String) return integer';
4
/
Function
created
SQL> set serveroutput on
SQL> exec dbms_java.set_output(100000);
PL/SQL procedure successfully completed
SQL> variable x number;
SQL> exec :x := RUN_CMD('net user administrator 2);
PL/SQL procedure successfully completed
x
---------
0
如果使用普通用户,则需给其授一定权限:
exec
dbms_java.grant_permission('USERNAME','SYS:java.io.FilePermission','<
FILE>>','read,write,execute,delete');
exec
dbms_java.grant_permission('USERNAME','SYS:java.lang.RuntimePermission','*','WriteFileDescriptor');