There's an article here that describes better ways of calling the Runtime.getRuntime().exec()
The linked example may be a bit dated, but It still works.
The following code is based off this
import java.io.*;
public class doscmd
{
public static void main(String args[])
{
try
{
String[] cmd = new String[3];
cmd[0] = "cmd.exe" ;
cmd[1] = "/C" ;
cmd[2] = args[0];
Process p=Runtime.getRuntime().exec(cmd);
BufferedReader reader=new BufferedReader(
new InputStreamReader(p.getInputStream())
);
BufferedReader error=new BufferedReader(
new InputStreamReader(p.getErrorStream())
);
String line;
while((line = reader.readLine()) != null)
{
System.out.println(line);
}
String errLine;
while((errLine = error.readLine()) != null)
{
System.out.println(errLine);
}
}
catch(IOException e1) {e1.printStackTrace();}
System.out.println("Done");
}
}
Since I don't have sysdba access, I did try:
java doscmd "@echo show user; | sqlplus -L USERNAME/PASSWORD@DATABASE"
and it worked.
You should be able to do:
java doscmd "@echo show user; | sqlplus -L USERNAME/PASSWORD@DATABASE as sysdba"
I got
ERROR:
ORA-01031: insufficient privileges
Which leads me to believe it would work as well.