So, I want to create a backup file for my mysql database.
However when i tried to run the code it takes too much time and still no response.
This is my code:
public void backup() {
String fileName = "";
URL url;
JFileChooser backupFile = new JFileChooser();
backupFile.setCurrentDirectory(new java.io.File("."));
backupFile.setDialogTitle("Select the Path of Backup");
backupFile.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
backupFile.setAcceptAllFileFilterUsed(false);
backupFile.setApproveButtonText("Backup Database");
backupFile.setSize(700, 400);
backupFile.setLocation(100, 100);
if (backupFile.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
try {
url = backupFile.getSelectedFile().toURL();
fileName = url.toString().replaceAll("file:/", "").trim();
System.out.println(fileName);
} catch (MalformedURLException e) {
e.printStackTrace();
}
} else {
System.out.println("No Selection");
}
try {
String dbName = AppVars.dbName;
String dbUser = AppVars.dbUserName;
String dbPass = AppVars.dbPassword;
if (!fileName.equals("") && fileName != null) {
String savePath = fileName + "ssmis.sql";
String executeCmd = AppVars.xamppUrl + "mysqldump -u " + dbUser + " -p " + dbPass + " --database " + dbName + " -r " + savePath;
System.out.println(executeCmd);
Process runtimeProcess = Runtime.getRuntime().exec(executeCmd);
int processComplete = runtimeProcess.waitFor();
System.out.println("Here");
if (processComplete == 0) {
JOptionPane.showMessageDialog(null, "Backup Successful", "Success", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "Backup Failed", "Failed", JOptionPane.INFORMATION_MESSAGE);
}
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Error at Backup " + ex);
}
}
What am i doing wrong?