0
我想學習JSP/Servlet的......我好不容易寫一個函數,整個數據庫的備份...檢查創建備份
package com.functions;
import java.io.*;
import java.io.IOException;
//import java.sql.Connection;
//import java.sql.PreparedStatement;
//import java.sql.ResultSet;
//import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//import com.functions.utility.DBConnector;
public class addMarks3 extends HttpServlet {
private static final long serialVersionUID = 8097085789553030042L;
protected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
System.out.println("--------------------");
System.out.println(" On Backup.java ");
System.out.println("--------------------");
fetchDataFromDB(request,response);
}
private void fetchDataFromDB(HttpServletRequest request,HttpServletResponse response){
try {
Runtime runtime = Runtime.getRuntime();
File backupFile = new File("C:/Users/Rohan/Desktop/LMS/backup.sql");
FileWriter fw = new FileWriter(backupFile);
Process child = runtime.exec("C:/Program Files (x86)/MySQL/MySQL Server 5.5/bin/mysqldump --user=root --password=root --lock-all-tables --opt dummy");
InputStreamReader irs = new InputStreamReader(child.getInputStream());
BufferedReader br = new BufferedReader(irs);
String line;
while((line=br.readLine()) != null) {
fw.write(line + "\n");
}
fw.close();
irs.close();
br.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
我仍然無法弄清楚如何驗證備份是否成功.. ?? 如何檢查備份是否成功?
PS:該文件沒有得到填充,每次我運行它....