Solved

calling an external java program from an oracle plsql procedure

Posted on 2004-10-07
2
724 Views
Last Modified: 2013-12-12
Hi,

I am calling a java program from an Oracle (9.1) stored procedure in a web browser

the oracle procedure is in schema OTIF_Executor that has
connect, resource, javasyspriv privileges.

the java program takes in a cmd and exeutes it on the operating system (windows server 2000).

I've had it working before my db crashed, I then rebuilt the database and now cannot get the procedure working.

--------------------------------------------------------------
begin..

lv_Cmd:= 'cscript //nologo D:\KPI\SCRIPTS\'||lv_file_name||'';
lv_Res:= pty_osutil_pkg.fn_runoscmd(lv_Cmd, my_tab);

 IF lv_Res = 1 THEN
           NULL;
 ELSE
          RAISE java_broken;
 END IF;


--PL\SQL wrapper for the java class ExecCmd which is stored in the database
FUNCTION fn_exec_cmd(p_shell VARCHAR2,p_cmd VARCHAR2,p_output IN OUT cmd_output) RETURN VARCHAR2
as
LANGUAGE JAVA NAME 'com.bat.utils.OSExecutor.executeCommand(java.lang.String,java.lang.String,oracle.sql.ARRAY[]) return java.lang.String';
      
            
FUNCTION fn_RunOsCmd(p_cmd IN VARCHAR2,   tab_cmdoutput IN OUT osutil_cmd_output) RETURN VARCHAR2 IS

tab_output cmd_output;
tab_errors cmd_output;                                    
lv_shell VARCHAR2(10);
lv_cmd VARCHAR2(255);
lv_success VARCHAR2(32767);
lv_output_count INTEGER :=0;

 BEGIN

   IF UPPER(substr(p_cmd,1,3)) ='RSH' THEN
           lv_shell := 'rsh';
        lv_cmd := substr(p_cmd,4,length(p_cmd)-3);
   ELSE
            lv_shell := 'cmd /c';
         lv_cmd := p_cmd;
   END IF;
 
   -- Execute command
 
   lv_success := fn_exec_cmd(lv_shell,lv_cmd, tab_output);
 
   IF tab_output.COUNT >0 THEN
      FOR x IN tab_output.first..tab_output.last LOOP                
              tab_cmdoutput(lv_output_count+x) := tab_output(x);
        END LOOP;
        lv_output_count := tab_cmdoutput.COUNT;
   END IF;
   
   RETURN lv_success;       

I did not have this issue before. I created a collection as:
CREATE OR REPLACE
type CMD_OUTPUT as table of varchar2(255)
/

again, originally this worked. I then started getting
ORA-06531: Reference to uninitialized collection

the only way I could get round this was to initialse the collection

e.g.

  IF UPPER(substr(p_cmd,1,3)) ='RSH' THEN
           lv_shell := 'rsh';
        lv_cmd := substr(p_cmd,4,length(p_cmd)-3);
   ELSE
            lv_shell := 'cmd /c';
         lv_cmd := p_cmd;
   END IF;
 
   tab_output:= CMD_OUTPUT('A','B','C','X','Y','Z');
   -- Execute command
 
   lv_success := fn_exec_cmd(lv_shell,lv_cmd, tab_output);

the procedure then has no error message but will not execute the command.

I know there are no issues with the java program so it has to be due to me putting
a) tab_output:= CMD_OUTPUT('A','B','C','X','Y','Z');
or
b) not setting up the correct privileges in the database

any ideas?
0
Comment
Question by:joehodge
2 Comments
 
LVL 23

Accepted Solution

by:
seazodiac earned 250 total points
ID: 12249167
glad that you nailed it.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to recover a database from a user managed backup

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question