Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

calling an external java program from an oracle plsql procedure

Posted on 2004-10-07
2
Medium Priority
?
736 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 1000 total points
ID: 12249167
glad that you nailed it.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

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 post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

670 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