I'm using process = Runtime.getRuntime().exec(cmd,null,new File(path)); to execute some SQL in file (abz.sql)
Command is:
"sqlplus "+ context.getDatabaseUser() + "/" + context.getDatabasePassword() + "@" + context.getDatabaseHost() + ":" + context.getDatabasePort() + "/" + context.getSid() + " @" + "\"" + script + "\""; String path=context.getReleasePath()+ "/Server/DB Scripts"; It is executing that file but not getting exit. Hence I tried using:
Writer out = new OutputStreamWriter(process.getOutputStream()); out.append("commit;\r\n"); out.append("exit \r\n"); System.out.println("---------"+out); out.close(); This it complete block that I m using:
if(context.getConnectionField()=="ORACLE") { String cmd= "sqlplus "+ context.getDatabaseUser() + "/" + context.getDatabasePassword() + "@" + context.getDatabaseHost() + ":" + context.getDatabasePort() + "/" + context.getSid() + " @" + "\"" + script +"\""; String path=context.getReleasePath()+ "/Server/DB Scripts"; process = Runtime.getRuntime().exec(cmd,null,new File(path)); out = new OutputStreamWriter(process.getOutputStream()); out.append("commit;\r\n"); out.append("exit \r\n"); System.out.println("---------"+out); out.close(); Integer result1 = null; while (result1 == null) { try { result1 = process.waitFor(); } catch (InterruptedException e) {} } if(process.exitValue() != 0) return false; return true; }