package com.casic.core.db; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class BackupSet { public static void delSchTask(String tn) { try { String cmd = "schtasks /delete /tn \"" + tn + "\" /f"; Runtime.getRuntime().exec(cmd); } catch (IOException e) { e.printStackTrace(); } } public static void addSchTask(String tn, String tr, String mo) { try { String cmd = "schtasks /create /tn \"" + tn + "\" /tr " + tr + " /sc minute /mo " + mo + " /ru \"System\""; Runtime.getRuntime().exec(cmd); } catch (IOException e) { e.printStackTrace(); } } public static void setParm4Oracle(String string, String path, String cycle) { } public static String doImp(String userName, String password, String orcSid, String fileName, String tbl) { String info = "导入完成!"; String[] cmds = new String[3]; cmds[0] = "cmd"; cmds[1] = "/C"; cmds[2] = "imp " + userName + "/" + password + "@" + orcSid + " fromuser=scott touser=" + userName + " file=" + fileName + " ignore=y destroy=y tables=("+tbl+")"; Process process = null; try { process = Runtime.getRuntime().exec(cmds); } catch (IOException e) { e.printStackTrace(); info = "导入出错!"; } boolean shouldClose = false; try { InputStreamReader isr = new InputStreamReader( process.getErrorStream()); BufferedReader br = new BufferedReader(isr); String line = null; while ((line = br.readLine()) != null) { System.out.println(line); if (line.indexOf("????") != -1) { shouldClose = true; break; } } } catch (IOException e) { e.printStackTrace(); info = "导入出错!"; } if (shouldClose) { process.destroy(); } int exitVal; try { exitVal = process.waitFor(); System.out.println(exitVal); } catch (InterruptedException e) { e.printStackTrace(); info = "导入出错!"; } return info; } }