Java掉.bat文件
sql腳本 存放於D:sqlplustest.sql
insert into ss values(11);
insert into ss values(12);
insert into ss values(13);
commit;
exit;
sql.bat腳本
@ECHO OFF
sqlplus -s username/password@sid @D:sqlplustest.sql
exit
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:sqlplussql.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("執行失敗.");
}
}
}