Solved

calling an external java program from an oracle plsql procedure

Posted on 2004-10-07
2
729 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 23

Accepted Solution

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

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

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…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Via a live example, show how to take different types of Oracle backups using RMAN.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

739 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