I'm trying to backup my database from a Java application. Currently, I'm using xampp as a localhost for database. I tried these codes in my program, but when I execute these codes my program goes on waiting state. When I execute the same code from command line it ask a password and after giving a password back up file backup.sql is created successfully.
The code I'm using is:
String executeCmd = "C:\\xampp\\mysql\\bin\\mysqldump.exe -u root -p db1 -r D:/mine/backup.sql";
Java code:
Process runtimeProcess;
try {
runtimeProcess = Runtime.getRuntime().exec(executeCmd);
int processComplete = runtimeProcess.waitFor();
if (processComplete == 0) {
System.out.println("Backup created successfully");
return true;
} else {
System.out.println("Could not create the backup");
}
} catch (Exception ex) {
ex.printStackTrace();
}