Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: java package to run OS command

RE: java package to run OS command

From: Jamadagni, Rajendra <Rajendra.Jamadagni_at_espn.com>
Date: Thu, 04 Dec 2003 09:24:25 -0800
Message-ID: <F001.005D8CCC.20031204092425@fatcity.com>


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



Rajendra dot Jamadagni at nospamespn dot com All Views expressed in this email are strictly personal. QOTD: Any clod can have facts, having an opinion is an art !

-----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?



This e-mail message is confidential, intended only for the named recipient(s) above and may contain information that is privileged, attorney work product or exempt from disclosure under applicable law. If you have received this message in error, or are not the named recipient(s), please immediately notify corporate MIS at (860) 766-2000 and delete this e-mail message from your computer, Thank you.
**************************************************************************************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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US