title: Java SQL output format table result
body: <p>I got everything working and it prints the right result with header (column name) and value. However I wanted to change a plain and unorganized result into a really nice output table format just like MySql table result with dash lines from query. How do I do that?</p>
  
  <pre><code>Statement statement = conn.createStatement();
  ResultSet rs = statement.executeQuery("SELECT * FROM quarter");
  ResultSetMetaData rsMetaData = rs.getMetaData();
  int numberOfColumns = rsMetaData.getColumnCount();
  for(int i = 1; i &lt;= numberOfColumns; i++)
  {
      System.out.print(rsMetaData.getColumnLabel(i) + " ");
  }
  System.out.println();
  while (rs.next())
  {
      for(int e = 1; e &lt;= rsMetaData.getColumnCount(); e++)
      {
          System.out.print(rs.getString(e) + " ");
      }
      System.out.println();
  }
  </code></pre>