Knowledge Base Nr: 00178 ExecuteCmd.java - http://www.swe-kaiser.de

Downloads:

Java: Systemaufrufe aus Oracledatenbank ausführen

  
//bauen: C:\j2sdk1.4.2_01\bin\javac ExecuteCmd.java
//aufruf: C:\j2sdk1.4.2_01\bin\java ExecuteCmd myprog
//db-upload: loadjava -u ***/***@*** ExecuteCmd.class -f

//wrapper für pl/sql:

CREATE OR REPLACE procedure procexecutecmd (s1 varchar2)
as language java
name 'ExecuteCmd.main(java.lang.String[])';

//aufruf von pl/sql aus:
exec procexecutecmd('myprog');

//java implementation:
import java.lang.Runtime;
import java.lang.Process;
import java.io.IOException;
import java.lang.InterruptedException;

class ExecuteCmd
{
static public final String strReturn = new String("lulli");

public static void main(String args[])
{
try
{
System.out.println("exec: " + args[0]);

Process p = Runtime.getRuntime().exec(args[0]);

try
{
p.waitFor();
}
catch (InterruptedException ie)
{
System.out.println("ERROR: waitFor(): " + ie);
}

System.out.println("exec returns: " + p.exitValue());
}
catch (IOException e)
{
System.out.println("ERROR: exec(): " + e);
}
}

public static String mymain(String args[])
{
return strReturn;
}

public static void main2(String args[], String strRet)
{
strRet = strReturn;
}
}