title: mySQL dump of individual tables in Java
body: <p>I am trying to connect to a mySQL database and dump a series of tables stored in an array. When I run my code I get the errors below. Can anyone help me figure out what files it cannot find? Is it the table it cannot find or the destination folder on the local machine? Also how do I know / how can I check if I am connected to the database correctly? </p>
  
  <pre><code>Connection dbConn = null;
      PreparedStatement stmt = null;
      ResultSet rs = null;
      long companyId = 1002;
      String query = "select mobile_no, creation_dt from subscriber where company_id=?";
      try {
          Class.forName("com.mysql.jdbc.Driver");
          String dbUrl = "jdbc:mysql://"+ dbHost + ":" + dbPort + "/" + dbName + "?autoReconnect=true";
  
          System.out.println(dbUrl);
  
          dbConn = DriverManager.getConnection(dbUrl, dbUserId, dbPassword);
          stmt = dbConn.prepareStatement(query);
          stmt.setLong(1, companyId);
          rs = stmt.executeQuery();
  
          java.util.Date date = new java.util.Date();
  
  
          System.out.println("STARTING DUMP");
          int i =0;
          dbTableName = dbTables.split(",");
          while(dbTableName[i] != null) {
              bPath = "\\" + dbHost + "." + dbTableName[i] + "." + new Timestamp(date.getTime()) + ".sql";
              System.out.println(bPath);
              Runtime.getRuntime().exec("mysqldump -u " + dbUserId + " -p " + dbPassword + " " + dbName + " " + dbTableName[i] + " --result-file=" + bPath);
              i++;
              //System.out.println(i);
          }
  
      } catch (Exception e) {
          System.err.println("Exception while reading info from database.");
          e.printStackTrace();
      } finally {
          try {
              if (rs != null) rs.close();
          } catch (Exception e) {
              System.err.println("Exception while closing result set!! - " + e.getMessage());
          }
          try {
              if (stmt != null) stmt.close();
          } catch (Exception e) {
              System.err.println("Exception while closing statment!! - " + e.getMessage());
          }
  
          try {
              if (dbConn != null) {
                  dbConn.close();
              }
          } catch (Exception e) {
              System.err.println("Exception while closing db connection!! - " + e.getMessage());
          }
      }
  </code></pre>
  
  <p>Errors:</p>
  
  <pre><code>Exception while reading info from database.
  java.io.IOException: Cannot run program "mysqldump": CreateProcess error=2, The system cannot find the file specified
      at java.lang.ProcessBuilder.start(ProcessBuilder.java:1042)
      at java.lang.Runtime.exec(Runtime.java:620)
      at java.lang.Runtime.exec(Runtime.java:450)
      at java.lang.Runtime.exec(Runtime.java:347)
      at Backup.main(Backup.java:80)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
  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:386)
      at java.lang.ProcessImpl.start(ProcessImpl.java:137)
      at java.lang.ProcessBuilder.start(ProcessBuilder.java:1023)
  </code></pre>