title: How to export a table from mysql using java
body: <p>I need to export a table from mysql using java. I tried using </p>
  
  <pre><code>public class automateExport {
      public static void main(String[] argv) throws Exception {
          String driverName = "com.mysql.jdbc.Driver";
          Class.forName(driverName);
          String serverName = "192.168.0.189";
          String mydatabase = "ArchiveIndexer";
          String url = "jdbc:mysql://" + serverName + "/" + mydatabase;
          String username = "username";
          String password = "password";
          Connection connection = DriverManager.getConnection(url, username, password);
          Statement stmt = connection.createStatement();
          String filename = "c:/outfiless.txt";
          String tablename = "D_Centre";
          System.err.println("SELECT * INTO OUTFILE \"" + filename + "\" FROM " + tablename);
          stmt.executeUpdate("SELECT * INTO OUTFILE \"" + filename + "\" FROM " + tablename);
          // stmt.executeQuery("SELECT * INTO OUTFILE \"" + filename + "\" FROM " + tablename);
          // stmt.execute("SELECT * INTO OUTFILE \"" + filename + "\" FROM " + tablename);
      }
  }
  </code></pre>
  
  <p>But this is throwing error like</p>
  
  <pre><code>"Exception in thread "main" java.sql.SQLException: Can not issue SELECT via executeUpdate().
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)
      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
      at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1764)
      at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1725)
      at automateexceldatabase.automateExport.main(automateExport.java:38)
  Java Result: 1"
  </code></pre>