/** * 1.通过java执行导出命令,导出dup数据文件到指定位置 * 2.清空表数据,为下一次解析准备 */ public void expDupDataByJaveProcess() { boolean success = true;//导致是否成功标识,成功修改为false String cmdSql="";//导出命令语句 try { SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd_hhmmss"); String time = format.format(new Date()); cmdSql="exp xxx/[email protected]/POMS file=d:\\dupDataFile\\sy_ems_data"+time+".dup log=d:\\dupDataFile\\sy_ems_data"+time+".log tables=(tab1,tab2...)"; //执行cmd命令 Process process = Runtime.getRuntime().exec(cmdSql); // 获取命令行交互的内容,process.getInputStream可获取正常反馈,process.getErrorStream只能获取错误反馈 BufferedReader inputBufferedReader = new BufferedReader( new InputStreamReader(process.getErrorStream())); // 如果错误反馈有内容,内容是警告而不是错误,则视为正常 String line; while ((line = inputBufferedReader.readLine()) != null){ if (!line.contains("[Warning]")) { success = false; } } // 等待命令执行结束 process.waitFor(); } catch (Exception e) { success = false; logger.error("===================================>导出dup文件数据失败:"+ e.getMessage()); } if (!success) { logger.info("========================================>>>>>>>>>>>>执行导出语句,导出dup文件数据成功!"+cmdSql); //清空表数据 logger.info(">>>>>>>>>>>>>>>>>>>>>>>>>>删除数据数据中...>>>>>>>>>>>>>>>>>>>>>>>>>>"); deleteData(); logger.info(">>>>>>>>>>>>>>>>>>>>>>>>>>删除数据数据完成!>>>>>>>>>>>>>>>>>>>>>>>>>>"); }else { logger.info("========================================>>>>>>>>>>>>执行导出语句,导出dup文件数据失败!"+cmdSql); } }
标签:java,success,process,导出,dup,cmdSql,logger From: https://www.cnblogs.com/yangcaiwen/p/17412127.html