Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: More on java procedures executing server-side processes
"Jeremy Ovenden" <jovenden_NOSPAM_at_hazelweb.co.uk> wrote in message
news:1011186266.980124_at_adsl.fast.net.uk...
> I know what I want to do is now possible - but have no knowledge of java
> which may present a problem!
>
> I have looked around this ng plus the obligatory asktom.oracle.com site
but
> cannot find the info I need.
>
> Essentially the plan is this:
>
> -- pl/sql calls a java procedure to execute a server-side shell script
> -- the display output from the execution of the shell script then needs to
> be written into an oracle table from where it can then be further
processed
> by pl/sql again
>
> I have taken Tom's examples and am now able to successfully execute my
shell
> script on the server from within pl/sql but what I don't know is how to
then
> 'capture' the data that is displayed back.
>
Have made some progress and have 'bodged' the following into Tom's java procedure (my additions have * at start of lines)
create or replace and compile
java source named "test"
as
import java.io.*;
import java.lang.*;
public class Test extends Object
{
public static int doit(String[] args)
{
Runtime rt = Runtime.getRuntime();
int rc = -1;
try
{
Process p = rt.exec(args[0]); int bufSize = 4096; BufferedInputStream bis = new BufferedInputStream(p.getInputStream(), bufSize); int len; byte buffer[] = new byte[bufSize]; // Echo back what the program spit out while ((len = bis.read(buffer, 0, bufSize)) != -1) System.out.write(buffer, 0, len); * String outtext = new String(buffer); * #sql {insert into cv (cv_text) values (:outtext) }; rc = p.waitFor();
e.printStackTrace(); rc = -1;
return rc;
}
}
}
/
I guess I would welcome any comments on what I have done - it *appears* to work (at least on a very small quantity of output text) but is it the (or a) *right* way to do it?
Thanks again (I appreciate that this is now perhaps a question that should be directed to a java ng...)
cheers
Jeremy
Received on Wed Jan 16 2002 - 10:26:54 CST
![]() |
![]() |