Java掉执行sql脚本的.bat文件
Java掉.bat文件
sql脚本 存放于D:\sqlplus\test.sql
insert into ss values(11);insert into ss values(12);insert into ss values(13);commit;exit;
sql.bat脚本
@ECHO OFFsqlplus -s username/password@sid @D:\sqlplus\test.sqlexit
Java代码
package com.tdxx.sqlplus;import java.io.IOException;public class ExecComm {public static void main(String[] args) {System.out.println("开始执行.");runBat();}public static void runBat() {Runtime rt = Runtime.getRuntime();Process ps = null;try {ps = rt.exec("cmd.exe /C start /b D:\\sqlplus\\sql.bat");ps.waitFor();} catch (InterruptedException e) {e.printStackTrace();} catch (IOException e1) {e1.printStackTrace();}int i = ps.exitValue();if (i == 0) {System.out.println("执行完成.");} else {System.out.println("执行失败.");}}}