execute sql in command line through sqlplus in java -


this question has answer here:

i have execute sql statement through sqlplus in java without using file in command line in sqlplus. need make connection , execute sql statement in same single line in java

echo "show user;" | sqlplus username/password sysdba 

i need find connection string that. how same thing in java??

every suggestion welcomed.

there's article here describes better ways of calling runtime.getruntime().exec()

the linked example may bit dated, still works.

the following code 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 don't have sysdba access, did try:

java doscmd "@echo show user; | sqlplus -l username/password@database" 

and worked.

you should able do:

java doscmd "@echo show user; | sqlplus -l username/password@database sysdba" 

i got

error: ora-01031: insufficient privileges 

which leads me believe work well.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -