Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: java package to run OS command
Here is a adoption for running the ls command ... be very careful with suspriv command, it is very powerful privilege. One could replace ls with rm and then you are doomed if oracle is running as root.
grant javasyspriv to system
/
create or replace type fileList as table of varchar2(255)
/
create or replace and compile java source named "DirList"
as
import java.io.*;
import java.sql.*;
import oracle.sql.*;
import oracle.jdbc.driver.*;
public class DirList
{
public static ARRAY getList(String directory)
throws SQLException{
File path = new File( directory );
Connection conn =
new OracleDriver().defaultConnection();
ArrayDescriptor descriptor =
ArrayDescriptor.createDescriptor( "FILELIST", conn );
return new ARRAY( descriptor, conn, path.list() );
}
}
/
create or replace function get_dir_list( p_directory in varchar2 )
return fileList
as language java
name 'DirList.getList( java.lang.String )
return oracle.sql.ARRAY.ARRAY';
/
set serveroutput on
declare
l_files fileList;
begin
dbms_output.enable(1000000);
l_files := get_dir_list( '/home/oraclei/code' );
for i in 1 .. l_files.count
loop
dbms_output.put_line( l_files(i) );
end loop;
end;
/
Raj
-----Original Message-----
Sent: Thursday, December 04, 2003 12:00 PM
To: Multiple recipients of list ORACLE-L
yeah, I'm trying to get away from C external procedures ...but java is beginning to look just as much a hassle.
Why is running a OS command such hassle?
**************************************************************************************5
-- Please see the official ORACLE-L FAQ: http://www.orafaq.net -- Author: Jamadagni, Rajendra INET: Rajendra.Jamadagni_at_espn.com Fat City Network Services -- 858-538-5051 http://www.fatcity.com San Diego, California -- Mailing list and web hosting services --------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).Received on Thu Dec 04 2003 - 11:24:25 CST