java程序还原MySQL数据库代码
2011-03-22 11:42
323 查看
private static void restore() {
String fpath="d:/xytx.sql";
Runtime rt=Runtime.getRuntime();
Process child=null;
try {
child=rt.exec("C://Program Files//MySQL//MySQL Server 5.5//bin//mysql -uroot -padmin crmsure");
} catch (IOException e) {
e.printStackTrace();
System.out.println("还原命令执行错误");
}
OutputStream out=child.getOutputStream();
String inStr;
StringBuffer sb=new StringBuffer();
String outStr;
InputStreamReader sr=null;
try {
sr = new InputStreamReader(new FileInputStream(fpath),"utf8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
System.out.println("文件流读入错误");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("文件路径错误");
}
BufferedReader br=new BufferedReader(sr);
try {
while((inStr=br.readLine())!=null){
sb.append(inStr+"/r/n");
}
} catch (IOException e) {
e.printStackTrace();
System.out.println("文件流读出错误");
}
outStr=sb.toString();
OutputStreamWriter writer=null;
try {
writer=new OutputStreamWriter(out,"utf8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
System.out.println("输出流错误");
}
try {
writer.write(outStr);
writer.flush();
} catch (IOException e) {
e.printStackTrace();
System.out.println("写入错误");
}
try {
writer.close();
out.close();
br.close();
System.out.println("还原成功");
} catch (Exception e) {
e.printStackTrace();
System.out.println("还原失败");
}
}
String fpath="d:/xytx.sql";
Runtime rt=Runtime.getRuntime();
Process child=null;
try {
child=rt.exec("C://Program Files//MySQL//MySQL Server 5.5//bin//mysql -uroot -padmin crmsure");
} catch (IOException e) {
e.printStackTrace();
System.out.println("还原命令执行错误");
}
OutputStream out=child.getOutputStream();
String inStr;
StringBuffer sb=new StringBuffer();
String outStr;
InputStreamReader sr=null;
try {
sr = new InputStreamReader(new FileInputStream(fpath),"utf8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
System.out.println("文件流读入错误");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("文件路径错误");
}
BufferedReader br=new BufferedReader(sr);
try {
while((inStr=br.readLine())!=null){
sb.append(inStr+"/r/n");
}
} catch (IOException e) {
e.printStackTrace();
System.out.println("文件流读出错误");
}
outStr=sb.toString();
OutputStreamWriter writer=null;
try {
writer=new OutputStreamWriter(out,"utf8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
System.out.println("输出流错误");
}
try {
writer.write(outStr);
writer.flush();
} catch (IOException e) {
e.printStackTrace();
System.out.println("写入错误");
}
try {
writer.close();
out.close();
br.close();
System.out.println("还原成功");
} catch (Exception e) {
e.printStackTrace();
System.out.println("还原失败");
}
}
相关文章推荐
- [知了堂学习笔记]_Java代码实现MySQL数据库的备份与还原
- Java程序调用系统命令进行mysql数据库的备份与还原,windows下mysql备份
- 用Java代码备份和还原MySQL数据库
- 用Java代码备份和还原MySQL数据库
- 使用Eclipse调试Java程序代码
- Java程序性能优化 程序和代码优化
- mysql数据库的连接以及增删改查Java代码实现(PreparedStatement版)
- 从 C/C++ 程序调用 Java 代码
- Java核心代码(六) 桌面程序--记事本
- 编写高质量代码--改善Java程序的151个建议--读书笔记
- 【Java】一个小程序,计算它包含的代码所需的耗时
- java--计算表达式实现程序代码
- FLASH安全沙箱服务器端程序代码(跨平台,C++/JAVA)
- 二叉树的建立和遍历程序代码(Java,C)
- 编写高质量代码:改善Java程序的151个建议-学习笔记(1-4章)
- 用BSF + Beanshell使Java程序能够运行字符串形式的代码(转载)
- [Java] 正则表达式 02 EmailSpider 抓邮件, CodeCounter 统计程序有效代码行数
- java web 程序---注册页面核心代码哈希Map
- 编写高质量代码:改善Java程序的151个建议(第1章:JAVA开发中通用的方法和准则___建议16~20)
- mysql数据库备份--java代码