今天弄了好久,终于搞定了这个问题。使用java代码实现数据库的备份。
- package cn.qm.db;
- import java.io.BufferedReader;
- import java.io.DataInputStream;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class Command {
- /*
- public static void main(String[] args) throws IOException {
- Command com = new Command();
- com.backupDatebase("localhost","root","root", "JXC", "D:/jxc.sql");
- }
- /**
- * 执行dos命令
- * @param cmd
- * @return
- */
- public String execCmd(String cmd) {
- StringBuffer sb = new StringBuffer("");
- StringBuffer str = new StringBuffer();
- str.append("cmd.exe /c \"").append(cmd).append("\"");
- System.out.println(str); //打印执行的命令
- Process ls_proc;
- try {
- ls_proc = Runtime.getRuntime().exec(str.toString());
- BufferedReader in = new BufferedReader(
- new InputStreamReader(
- new DataInputStream(ls_proc.getInputStream())));
- String ss = "";

本文展示了如何使用Java代码在JSP页面上执行MySQL数据库的备份和恢复操作。通过调用`Command`类进行数据库备份,以及`Recover`类进行数据恢复,实现了对数据库的完整生命周期管理。

最低0.47元/天 解锁文章
1685

被折叠的 条评论
为什么被折叠?



