Java掉执行sql脚本的.bat文件
2013-09-04 20:07:48 来源:WEB开发网 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 OFF
sqlplus -s username/password@sid @D:\sqlplus\test.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:\\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("执行失败.");
}
}
}
更多精彩
赞助商链接