Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to run an exe from an oracle trigger.

591089Aug 3 2007 — edited Dec 9 2011
Hi!

I want to run an exe using trigger. I have written a java class file loaded it to oracld db using loadjava. Now I am accessing that class file from an oracle procedure.The code is.

import java.io.*;
import java.util.*;

public class CommandExection {

public static void Command(String commandline) {

try {

String line;

Process p = Runtime.getRuntime().exec(commandline);

BufferedReader input =

new BufferedReader

(new InputStreamReader(p.getInputStream()));

while ((line = input.readLine()) != null) {

System.out.println(line);

}

input.close();

}

catch (Exception err) {

err.printStackTrace();

}
}

an oracle procedure calling the Command method in CommandExection class is,

create or replace procedure CommandExection(path in varchar)
as
language java
name 'CommandExection.Command(java.lang.String)';

I executed the procedure and ended up with the error.

SQL> set serverout on size 1000000
SQL>
SQL> exec dbms_java.set_output(1000000)

PL/SQL procedure successfully completed.

SQL>
SQL> begin
2 CommandExection('D:exeapp.exe');
3 end;
4 /
java.io.IOException: The handle is invalid.
at oracle.aurora.java.lang.OracleProcess.create(Native Method)
at oracle.aurora.java.lang.OracleProcess.construct(OracleProcess.java:25)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:566)
at java.lang.Runtime.exec(Runtime.java:428)
at java.lang.Runtime.exec(Runtime.java:364)
at java.lang.Runtime.exec(Runtime.java:326)
at CommandExection.Command(CommandExection:12)

PL/SQL procedure successfully completed.

Please help me with this.
My objective is to run an exe from an oracle trigger. I am using oracle 10g
desperately waiting for the reply.
Thank you.
Prashant
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 6 2012
Added on Aug 3 2007
22 comments
10,380 views