I need to avoid the error and store database backup in separate file path using mysqldump
public class NewClass {
public static void main(String args[]) throws IOException, SQLException {
String dbName = "test";
String dbUser = "root";
String dbPass = "root";
try {
String executeCmd = "";
executeCmd = "mysqldump -u " + dbUser + " -p" + dbPass + " " + dbName + " -r backup.sql";
Process runtimeProcess = Runtime.getRuntime().exec(executeCmd);
int processComplete = runtimeProcess.waitFor();
if (processComplete == 0) {
System.out.println("Backup taken successfully");
} else {
System.out.println("Could not take mysql backup");
}
} catch (InterruptedException ex) {
Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
ERROR:run: Exception in thread "main" java.io.IOException: Cannot run program "mysqldump": CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessBuilder.start(ProcessBuilder.java:1042) at java.lang.Runtime.exec(Runtime.java:615) at java.lang.Runtime.exec(Runtime.java:448) at java.lang.Runtime.exec(Runtime.java:345) at mypkg.NewClass.main(NewClass.java:27) Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessImpl.create(Native Method) at java.lang.ProcessImpl.(ProcessImpl.java:288) at java.lang.ProcessImpl.start(ProcessImpl.java:133) at java.lang.ProcessBuilder.start(ProcessBuilder.java:1023) ... 4 more Java Result: 1 BUILD SUCCESSFUL (total time: 0 seconds)
mysqldump
program on your%PATH%
or$PATH
? – mthmulders