title: Backup mysql database using java
body: <p>My application contains one java frame for backup.I add the following code in a public class and call that.My need is to create the MySQL dump file in application.How can i do that using java code,The following set of code will give you what exactly do in my program.</p>
  
  <pre><code>  public boolean backupDB() {
  
      connection = (Connection) dbSource.getConnection();
  
  
      String executeCmd = "\"C:\\Program Files\\MySQL\\MySQL Server 5.1\\bin\\mysqldump\"  -u root -p pass macfast -r backup.sql";
      Process runtimeProcess;
      try {
  
          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;
  }
  </code></pre>
  
  <p>I call this by</p>
  
  <pre><code> private void backupbtnActionPerformed(java.awt.event.ActionEvent evt) {
      backupDB();
  }
  </code></pre>
  
  <p>It stuck when i am trying to run.After run i can't close the frame.only possible through taskmanager.why?</p>