pageEncoding="UTF-8" import="java.lang.*,java.io.*,java.util.*"%>
Runtime runtime = Runtime.getRuntime();
// 将/data/backup.sql 还原到 192.168.0.96 上的demo库 账号密码为 root root
String restore = "mysql -u root -proot -h 192.168.0.96 demo
String[] command = new String[]{"/bin/bash","-c",restore};
Process process = runtime.exec(command);
// 输出执行结果
InputStreamReader in = new InputStreamReader(process.getInputStream());
BufferedReader br = new BufferedReader(in);
String line = null;
while((line = br.readLine()) != null){
System.out.println(line);
}
br.close();
in.close();
// 输出错误信息
InputStreamReader in2 = new InputStreamReader(process.getErrorStream());
BufferedReader br2 = new BufferedReader(in2);
String line2 = null;
while((line2 = br2.readLine()) != null){
System.out.println("="+line2);
}
br2.close();
in2.close();
%>
[为什么加/bin/bash -c]