Mysql backup by java

Asked

Viewed 810 times

1

Good afternoon, I have a cmd that correctly backs up my database, but when running in java it does not open the cmd in the expected way, it follows the code:

package sistemaMiriam.backup;

import java.io.IOException;

public class MySQLBackup {
public static void main(String[] args){
    String comando = "C:\\xampp\\mysql\\bin\\mysqldump sistema_miriam -u root -p ";
    try {
        Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL "+comando);

    } catch (IOException e) {
        e.printStackTrace();
    }
}
}

If I put C:\\xampp\\mysql\\bin\\mysqldump sistema_miriam -u root -p >nomeParaArquivo.sqlhe executes the >nomeParaArquivo.sqlas if it were a table and not create a file with the data from the bd

  • rundll32 SHELL32.DLL,ShellExec_RunDLL and comando are two different commands right? Try this http://answall.com/a/57076/3635, there explains the use of &, perhaps the ProcessBuilder can solve your problem

  • I tried to change, according to an example I saw on the net, Runtime.getRuntime().exec("mysqldump --opt --user=root --password sistema_miriam > my_db.sql"); but says that the path was not found, some suggestion?

  • Matheus this means that mysql is not configured in the PATH environment variable, once I have a time I formulate a response.

  • Okay, thank you very much

  • I edited the question, I had an evolution, some suggestion?

1 answer

0

What may be happening is that you are not allowed to run files in the specified directory (C: Program Files (x86) Easyphp-Devserver-14.1VC11 binaries mysql bin _sqldump.bat). Try running a test in a directory created by you at the root of C: or D: . If this is the problem try running the java program with administrator permissions.

  • I tried to change the directory and still not working, I tried all the codes available on the internet and none worked, always points as incorrect path, if you have a very simple code that backup by the application of a light, pq ta dificil... :/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.