jsp中怎么备份和恢复Mysql?最好能提供JSP页面和源代码
展开全部
package mysql;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
public class MySQL {
public MySQL(){
}
public void backup(String mysql) throws IOException{
//String command="cmd /c mysqldump -u "+username+" -p "+pwd+" "+dataname+" > "+path;
Runtime r=Runtime.getRuntime();
Process p;
p = r.exec(mysql);
BufferedReader br=new BufferedReader(new InputStreamReader(p.getErrorStream()));
StringBuffer sb=new StringBuffer();
String inline;
while(null!=(inline=br.readLine())){
sb.append(inline).append("\n");
}
}
public static void load() {
try {
String fPath = "e:/zizhu/bak/20091112003349.sql";
Runtime rt = Runtime.getRuntime();
// 调用 mysql 的 cmd:
Process child = rt.exec("mysql -u root -p admin info");
OutputStream out = child.getOutputStream();//控制台的输入信息作为输出流
String inStr;
StringBuffer sb = new StringBuffer("");
String outStr;
BufferedReader br=new BufferedReader(new InputStreamReader( new FileInputStream(fPath), "utf8"));
while ((inStr = br.readLine()) != null) {
sb.append(inStr + "\r\n");
}
outStr = sb.toString();
OutputStreamWriter writer = new OutputStreamWriter(out, "utf8");
writer.write(outStr);
writer.flush();
// 别忘记关闭输入输出流
out.close();
br.close();
writer.close();
System.out.println("/* Load OK! */");
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws IOException {
MySQL my = new MySQL();
String command="cmd /c mysqldump -u "+"root"+" -p"+"admin"+" "+"info"+" > "+"d:/info.sql";
//my.load();
my.backup(command);
//String command="cmd /c mysqldump -u "+"username"+" -p "+"pwd"+" "+"dataname"+" > "+"path";
//System.out.println(command);
}
}
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
public class MySQL {
public MySQL(){
}
public void backup(String mysql) throws IOException{
//String command="cmd /c mysqldump -u "+username+" -p "+pwd+" "+dataname+" > "+path;
Runtime r=Runtime.getRuntime();
Process p;
p = r.exec(mysql);
BufferedReader br=new BufferedReader(new InputStreamReader(p.getErrorStream()));
StringBuffer sb=new StringBuffer();
String inline;
while(null!=(inline=br.readLine())){
sb.append(inline).append("\n");
}
}
public static void load() {
try {
String fPath = "e:/zizhu/bak/20091112003349.sql";
Runtime rt = Runtime.getRuntime();
// 调用 mysql 的 cmd:
Process child = rt.exec("mysql -u root -p admin info");
OutputStream out = child.getOutputStream();//控制台的输入信息作为输出流
String inStr;
StringBuffer sb = new StringBuffer("");
String outStr;
BufferedReader br=new BufferedReader(new InputStreamReader( new FileInputStream(fPath), "utf8"));
while ((inStr = br.readLine()) != null) {
sb.append(inStr + "\r\n");
}
outStr = sb.toString();
OutputStreamWriter writer = new OutputStreamWriter(out, "utf8");
writer.write(outStr);
writer.flush();
// 别忘记关闭输入输出流
out.close();
br.close();
writer.close();
System.out.println("/* Load OK! */");
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws IOException {
MySQL my = new MySQL();
String command="cmd /c mysqldump -u "+"root"+" -p"+"admin"+" "+"info"+" > "+"d:/info.sql";
//my.load();
my.backup(command);
//String command="cmd /c mysqldump -u "+"username"+" -p "+"pwd"+" "+"dataname"+" > "+"path";
//System.out.println(command);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询