title: I am trying to export MySql data to a file using Java, but I am not able to get the table headers
body: <p>I am able to export mysql to csv file but i am not getting table headers, I want headers to be displayed when my file gets saved to my system.</p>
  
  <p>This is the java code which I am using:</p>
  
  <pre><code>import java.io.*;
  import java.sql.*;
  
  public class ExportData {
  
      public static void main(String args[]) {
          String Driver;
          Statement stmt;
          Driver = "com.mysql.jdbc.Driver";
          Connection con = null;
  
          try {
              Class.forName(Driver);
              con = DriverManager.getConnection(
                    "jdbc:mysql://localhost/emp", "root", "");
              if (!con.isClosed()) {
                  System.out.println("Successfully connected to MySQL DataBase \n");
                  stmt = con.createStatement();
                  String filename = "C:/2.txt";
                  String tablename = "employees";
                  String sql;
                  stmt.executeUpdate("SELECT * INTO OUTFILE \""
                          + filename + "\" FROM " + tablename);
              }
          } catch (Exception e) {
              System.err.println("Exception: " + e.getMessage());
          } finally {
              try {
                  if (con != null) {
                      con.close();
                  }
              } catch (SQLException e) {
              }
          }
      }
  }
  </code></pre>