您现在的位置: 万盛学电脑网 >> 程序编程 >> 网络编程 >> 编程语言综合 >> 正文

Java掉执行sql脚本的.bat文件

作者:佚名    责任编辑:admin    更新时间:2022-06-22

   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("执行失败.");

  }

  }

  }