I need to be able to capture the code from my PL/SQL SP and act accordingly. How can I do this? Here is all my code:
JAVA SP:
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED Command
AS
import java.io.*;
import java.util.*;
public class Command{
public static int run(String cmdText)
throws IOException, InterruptedException, Exception
{
int rtn;
try {
Runtime rt = Runtime.getRuntime();
Process prcs = rt.exec(cmdText);
rtn = prcs.waitFor();
}
catch (Exception e) {
//System.out.println("Transaction failed: " + e.getMessage());
return -1;
}
return rtn;
}
}
/
The Java returns a desired code for me now but how do I get it back to my PL/SQL? Here is the next part:
CREATE OR REPLACE PROCEDURE runoscommand(cmd IN VARCHAR2)
AS LANGUAGE JAVA
NAME 'Command.run(java.lang.String)';
/
Here is the snipit of PL/SQL code that calls runoscommand above. It is part of a Stored Procedure. The return code needs to return to runoscommand and then to my PL/SQL Stored Procedure.
IF p_comp_fmt = 'Z' THEN
loscmd := 'zip -j -1 ' || l_zip_dir || '\' || p_comp_fname || ' ' || l_zip_dir || '\' || p_filename ;
-- Compress the file.
runoscommand(loscmd);
utl_file.fremove(p_dir, p_filename);
ELSIF p_comp_fmt = 'G' THEN
loscmd := 'gzip -f ' || l_zip_dir || '/' || p_filename || ' ' || l_zip_dir || '/' || p_comp_fname;
-- Compress the file.
runoscommand(loscmd);
utl_file.fremove(p_dir, p_filename);
END IF;
David