Java执行exp导出命令

   由于需要提供b/s下页面数据导出功能.现在提供了一个JSP页面操纵数据导出功能的方法.
给出了输出条件,如
用户名,密码,实例名,数据表名,输出文件,日志文件,查询条件等.

接收用户输入参数值的方法如下:(为了简单实现功能,采用了jsp+servlet方式).可以将下面done(***)方法的返回值,输出至页面显示.
方法代码段如下:(供参考)

public String done(String username, String password, String sid,
String tables, String file, String log, String query) {
String[] cmds = new String[3];
cmds[0] = "cmd";
cmds[1] = "/C";
cmds[2] = "exp " + username + "/" + password + "@" + sid + " tables="
+ tables + " file=" + file + " log=" + log + " query='" + query
+ "'"; // 此处可以进行配置管理
Process process = null;
try {
process = Runtime.getRuntime().exec(cmds);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
boolean close = false;
String s = "";
try {
InputStreamReader isr = new InputStreamReader(process
.getErrorStream());
BufferedReader br = new BufferedReader(isr);
String line = "";
while ((line = br.readLine()) != null) {
s = s + br.readLine() + "<br>";
// invalid username/password logon denied EXP-00056
// invalid username/password logon denied ORA-01017
// 表不存在 EXP-00011
// 无法处理服务名 ORA-12154
// 导出终止失败 EXP-00000
if (line.indexOf("EXP-00056") != -1
|| line.indexOf("ORA-01017") != -1
|| line.indexOf("EXP-00011") != -1
|| line.indexOf("ORA-12154") != -1
|| line.indexOf("EXP-00000") != -1) {
close = true;
break;
}
}
} catch (IOException ioe) {
close = true;
}
if (close)
process.destroy();
try {
int exitVal = process.waitFor();
System.out.println("exitVal:" + exitVal);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return s;

}

你可能感兴趣的:(java,jsp,servlet,配置管理,idea)