title: How to run a MySQL script using ProcessBuilder?
body: <p>I have a SQL script which I would like to execute from a Java class, running on Windows. I am currently trying to do this using <code>ProcessBuilder</code> in the following function:</p>
  
  <pre><code>public static boolean runSqlScript(String filename, String user, String password) {
      ProcessBuilder pb = new ProcessBuilder("mysql", "-u"+user, "-p"+password, "&lt; "+ filename);
      try {
          Process pr = pb.start();
          BufferedReader errors = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
          BufferedReader output = new BufferedReader(new InputStreamReader(pr.getInputStream()));
          while (pr.isAlive()) {
              try {
                  System.err.println(errors.readLine());
                  System.out.println(output.readLine());
                  Thread.sleep(10);
              } catch (InterruptedException e) {
                  break;
              }
          }
          System.err.println(errors.readLine());
          System.out.println(output.readLine());
  
          int status = pr.exitValue();
          return (status == 0);
      } catch (IOException e) {
          System.err.println("Error running command: " + e.getMessage());
          return false;
      }
  }
  </code></pre>
  
  <p>The filename is the absolute path to the script, and the user and password are verified correct. But when I run this, I get the error:</p>
  
  <pre><code>ERROR 1102 (42000): Incorrect database name '&lt; c:/path/to/script.sql'
  </code></pre>
  
  <p>Why is it interpreting that as a database name rather than a command line argument? Can I use ProcessBuilder to run the script like this?</p>