我尝试从我的 java 应用程序(使用 wamp 服务器)备份 mysql 数据库,但它不起作用,它总是显示消息“无法创建备份”。这是我从这个线程中获取的代码: Backup a mysql [xampp] database in java
public static void saveBdd(){
String path = null;
String user = "root";
Process p = null;
JFileChooser fc = new JFileChooser();
fc.setDialogTitle("Choisir l'emplacement de la sauvegarde");
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.setAcceptAllFileFilterUsed(false);
fc.showOpenDialog(startPage);
String date = new SimpleDateFormat("dd-MM-yyyy").format(new Date());
try {
File f = fc.getSelectedFile();
path = f.getAbsolutePath();
path = path.replace('\\', '/');
path = path+"/bcpbdd_"+date+".sql";
} catch (Exception e) {
e.printStackTrace();
}
try{
Runtime runtime = Runtime.getRuntime();
p=runtime.exec("C:/wamp64/bin/mysql/mysql5.7.23/bin/mysqldump -u " + user + " --add-drop-database -B bcpbdd -r "+path);
int processComplete = p.waitFor();
if (processComplete==0) {
StartPage.afficheMessage("Backup Created Success!");
} else {
StartPage.afficheMessage("Can't create backup.");
}
} catch (Exception e) {
StartPage.afficheMessage(e.getMessage());
}
}
慕妹3242003
HUH函数
相关分类