下面是一个备份数据库的servletpackagecom.car.servlet;importjava.io.File;importjava.io.IOException;importjava.io.InputStreamReader;importjava.io.LineNumberReader;importjava...
下面是一个备份数据库的servlet
package com.car.servlet;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class DatabaseBackupServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
req.setCharacterEncoding("GBK");
String time=req.getParameter("time");
//System.out.println("time="+time);
String command = "cmd /c C:/Documents and Settings/User>mysqldump -uroot -proot car_database > E:/"+time+"_驾校系统数据库.sql";
req.setAttribute("sql", "E:/数据库备份/"+time+"_驾校系统数据库.sql");
File path=new File("E:/数据库备份");
try {
if(!path.exists()){
path.mkdir();
path.mkdirs();
}
Process process = Runtime.getRuntime().exec(command);
} catch (IOException e) {
e.printStackTrace();
}
req.getRequestDispatcher("database_backup.jsp").forward(req, resp);
}
}
该文件是在E盘出现了 但是里面是空的 哪位高手帮忙解决
展开