public String startLoadDatavase(){
String fpath="d:/scnudims.sql";//先前备份的文件的路径
//String path="C://Program Files//MySQL//MySQL Server 5.1//bin//mysql -uroot -proot -h 10.10.6.29 hms";
String path="C://Program Files//MySQL//MySQL Server 5.1//bin//mysql -uroot -p11 -h localhost scnudims";
/*D:MySQL Server 5.1//bin//mysql 为mysql.exe所在的位置,-u root -pkuan -h localhost 分别为角色,密码,服务器,mytest为要恢复的数据库*/
try {
Process process=Runtime.getRuntime().exec(path);
OutputStream output = process.getOutputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fpath), "utf8"));
String in;
StringBuffer buffer = new StringBuffer("");
while ((in = br.readLine()) != null) {
buffer.append(in + "/r/n");
}
String out = buffer.toString();
OutputStreamWriter writer = new OutputStreamWriter(output, "utf8");
writer.write(out);
writer.flush();
output.close();
br.close();
writer.close();
System.out.println( "数据库还原成功!");
return SUCCESS;
} catch (Exception e) {
e.printStackTrace();
}
return "loaddatabase";
}
String fpath="d:/scnudims.sql";//先前备份的文件的路径
//String path="C://Program Files//MySQL//MySQL Server 5.1//bin//mysql -uroot -proot -h 10.10.6.29 hms";
String path="C://Program Files//MySQL//MySQL Server 5.1//bin//mysql -uroot -p11 -h localhost scnudims";
/*D:MySQL Server 5.1//bin//mysql 为mysql.exe所在的位置,-u root -pkuan -h localhost 分别为角色,密码,服务器,mytest为要恢复的数据库*/
try {
Process process=Runtime.getRuntime().exec(path);
OutputStream output = process.getOutputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fpath), "utf8"));
String in;
StringBuffer buffer = new StringBuffer("");
while ((in = br.readLine()) != null) {
buffer.append(in + "/r/n");
}
String out = buffer.toString();
OutputStreamWriter writer = new OutputStreamWriter(output, "utf8");
writer.write(out);
writer.flush();
output.close();
br.close();
writer.close();
System.out.println( "数据库还原成功!");
return SUCCESS;
} catch (Exception e) {
e.printStackTrace();
}
return "loaddatabase";
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货