1

I was trying to execute the mysql command using java but this always keeps giving error.

    String dbName = "dth";
    String dbUser = "root";
    String dbPass = "root";

    String executeCmd = "";
    executeCmd = "mysqldump -u " + dbUser + " -p" + dbPass + " " + dbName + " -r    C:\\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 (Exception e) {
    System.out.println(e.getMessage());
}

I tried the above code but I couldn't get it done, keeps giving me

CreateProcess error=2, The system cannot find the file specified error.

I have tried it by creating a .sql file on the location and still I get the same error.

3
  • 1
    Could it be that it fails to find mysqldump? Perhaps it's not in your path? Commented Feb 17, 2013 at 4:46
  • 1
    I think its similar to thread.... stackoverflow.com/questions/13376132/… Commented Feb 17, 2013 at 4:52
  • I did that but now it causes the program to never stop. i.e. It starts, it does create a backup.sql file but it never stops! like an infinite loop. Commented Feb 17, 2013 at 5:06

1 Answer 1

1

Add the directory in which mysqldump resides into your path environment variable or use the full pathname I.e c:\directory\mysqldump

Sign up to request clarification or add additional context in comments.

7 Comments

I did that but now it causes the program to never stop. i.e. It starts, it does create a backup.sql file but it never stops! like an infinite loop.
Are you sure it's just not waiting for the dump to finish? I would check the running processes to make sure it's done.
ok it was not that, I was experimenting with the string and left a space after the -p and caused the infinite error.
One more question why the backup from PHPmyadmin is like 3.5MB and from mysqldump only 27Kb? is there anything missing?
Thats not right, I'm not a mysql expert but the -r option in your command doesnt look right. Try replacing "-r" with ">".
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.