Try to backup mysql DB from Java application (IDE Netbeans) using the following command but can't seem to find the file even though I specified a path:
Runtime.getRuntime().exec("C:\\Program Files\\MySQL\\MySQL Server 5.6\\bin\\mysqldump "+fisier.getName()+" > C:\\"+fisier.getName()+".sql;");
Also, I don't receive any errors, so I assumed that the backup has been done. How can I find the file? Regarding fisier.getName(): File fisier = jFileChooserSave.getSelectedFile();
For non-windows users:
String dump = "mysqldump -usome_user -psome_pass database_name > path/to/file.sql";
String[] cmdarray = {"/bin/sh","-c", dump};
Process p = Runtime.getRuntime().exec(cmdarray);
if (p.waitFor() == 0) {
// Everything went fine
} else {
// Something went wrong
}
Using the cmd array is important. Otherwise exec cannot parse '>' and file name and you will get an error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With