/*************************************************************************/
save the following as vijayDemo.java
/*************************************************************************/
import java.io.*;
import java.util.*;
public class vijayDemo
{
static public String[] runCommand(String cmd) throws IOException
{
// set up list to capture command output lines
ArrayList list = new ArrayList();
// start command running
Process proc = Runtime.getRuntime().exec(cmd);
// get command's output stream and
// put a buffered reader input stream on it
InputStream istr = proc.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(istr));
// read output lines from command
String str;
while ((str = br.readLine()) != null)
list.add(str);
// wait for command to terminate
try
{
proc.waitFor();
}
catch (InterruptedException e)
{
System.err.println("process was interrupted");
}
// check its exit value
if (proc.exitValue() != 0)
System.err.println("exit value was non-zero");
// close stream
br.close();
// return list of strings to caller
return (String[])list.toArray(new String[0]);
}
public static void main(String args[]) throws IOException
{
try
{
// run a command
String outlist[] = runCommand("/bin/vmstat 2 20");
//String outlist[] = runCommand("/u02/home/usupport/ashehade/java/test");
// uncomment this line an comment above if you want to execut
// a c executable called test.
// display its output
for (int i = 0; i < outlist.length; i++)
System.out.println(outlist[i]);
}
catch (IOException e)
{
System.err.println(e);
}
}
}
/*************************************************************************/
Load the code into datbase
/*************************************************************************/
loadjava -u apps/apps vijaydemo.java
/*************************************************************************/
create the procedure for stored java code
/*************************************************************************/
create or replace procedure lsfromjava as
language java name 'vijaydemo.main(java.lang.String[])';
/
Test it
SQL> set serverout on
SQL call dbms_java.set_output(2000);
SQL> execute lsfromjava










