title: Mysql database backup by using java
body: <p>I am going to take database backup by using java code.This code is excuting fine but I am getting    <strong>int processComplete = runtimeProcess.waitFor();</strong> This method calling is returning the integer as 1. So finally I am getting the message as could not create backup as sop.</p>
  
  <pre><code>public static void main(String[] args) {
  
          String path = "D:/databasebackup/databasbac.sql";
          String username = "root";
          String password = "";
          String dbname = "rac";
          String executeCmd = "&lt;Path to MySQL&gt;/bin/mysqldump -u " + username + " -p" + password + " --add-drop-database -B " + dbname + " -r " + path;
          Process runtimeProcess;
          try {
  //            System.out.println(executeCmd);//this out put works in mysql shell
              runtimeProcess = Runtime.getRuntime().exec(new String[] { "cmd.exe", "/c", executeCmd });
              System.out.println(executeCmd);
  //            runtimeProcess = Runtime.getRuntime().exec(executeCmd);
              int processComplete = runtimeProcess.waitFor();
              System.out.println("processComplete"+processComplete);
              if (processComplete == 0) {
                  System.out.println("Backup created successfully");
  
              } else {
                  System.out.println("Could not create the backup");
              }
          } catch (Exception ex) {
              ex.printStackTrace();
          }
  
      }
  </code></pre>