title: backup mysql database java code
body: <p>I tried to run the following code which is to create a <strong>backup of my database</strong> but it shows some run time errors.</p>
  
  <p>But, I tried to run the <strong>System.out.println() output</strong> part, (which I've commented in the given code) <strong>in mysql shell and it worked</strong>.</p>
  
  <p>It shows io file problem. Plz somebody help me.</p>
  
  <pre><code>package files;
  
   public class tableBackup_1 {
  
  public boolean tbBackup(String dbName,String dbUserName, String dbPassword, String path) {
  
      String executeCmd = "mysqldump -u " + dbUserName + " -p" + dbPassword + " --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(executeCmd);
              int processComplete = runtimeProcess.waitFor();
  
                  if (processComplete == 0)
                  {
                      System.out.println("Backup created successfully");
                      return true;
                  }
                  else
                  {
                      System.out.println("Could not create the backup");
                  }
          } catch (Exception ex)
          {
              ex.printStackTrace();
          }
  return false;
  }
  
  public static void main(String[] args){
  
          tableBackup_1 bb = new tableBackup_1();
          bb.tbBackup("test","harin","1234","C:/Users/Master/Downloads/123.sql");
  
  }
  }
  </code></pre>
  
  
  
  <pre><code>    mysqldump -u harin -p1234 --add-drop-database -B test -r C:/Users/Master/Downloads/123.sql
  java.io.IOException: Cannot run program "mysqldump": CreateProcess error=2, The system cannot find the file specified
          at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
          at java.lang.Runtime.exec(Runtime.java:593)
          at java.lang.Runtime.exec(Runtime.java:431)
          at java.lang.Runtime.exec(Runtime.java:328)
          at files.tableBackup_1.tbBackup(tableBackup_1.java:12)
          at files.tableBackup_1.main(tableBackup_1.java:34)
  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.&lt;init&gt;(ProcessImpl.java:81)
          at java.lang.ProcessImpl.start(ProcessImpl.java:30)
          at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)
          ... 5 more
  </code></pre>