public void expOracle(){
Runtime rt = Runtime.getRuntime();
Process processexp = null;//进程
String exp = "exp ccnuodms1/ccnuodms1@33.4 file=d:/sql.dmp";
try {
processexp = rt.exec(exp);
if (processexp.waitFor()!=0) {
System.err.println("exit value = " +
processexp.exitValue());
}
System.out.println(processexp);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
方法有误: 该方法的确能够生成数据库文件(目前在服务器上测试1个小时是没完成,而且没进展的迹象,且数据库只有1M左右),但是如果停掉业务系统后 sql.dmp 中内容会马上慢慢增加完成(大概5秒钟左右能够完成)。如果业务系统不停止, 数据库文件内容不全。同时会有一个叫exp.exe的进程,如果再次让java导出的话也会增加一个exp.exe的进程。
后面下午没事又找了下java导出Oracle
public void expOracle(){
Runtime rt = Runtime.getRuntime();
Process processexp = null;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss"); // 将日期格式化
String systemDate = simpleDateFormat.format(new Date(System.currentTimeMillis()));
String exp = "exp ccnuodms1/ccnuodms1@33.4 file='"+"d:/sql"+systemDate+".dmp'";
try {
processexp = rt.exec(exp);
Scanner scanner1 = new Scanner(processexp.getErrorStream());
StringBuilder result = new StringBuilder();
while (scanner1.hasNextLine()) {
result.append(scanner1.nextLine());
result.append(System.getProperty("line.separator"));
}
System.out.println(processexp.waitFor());
if(processexp.waitFor()!=0){
processexp.destroy();
}else {
processexp.destroy();
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}finally{
}
}
这个是可以将Oracle数据库导出来的。