code: public static void print(ResultSet rs, PrintStream out) throws SQLException {
      ResultSetMetaData meta = rs.getMetaData();
      int columns = meta.getColumnCount();
      for (int i = 0; i < columns; i++) {
        if (i > 0) {
          out.print(",");
        }
        out.print("\"");
        out.print(meta.getColumnName(i + 1));
        out.print("\"");
      }
      out.println();
  
      while (rs.next()) {
        for (int i = 0; i < columns; i++) {
          if (i > 0) {
            out.print(",");
          }
          String value = rs.getString(i + 1);
          if (value != null) {
            out.print("\"");
            out.print(value.replaceAll("\"", "\"\""));
            out.print("\"");
          } else {
            out.print("NULL");
          }
        }
        out.println();
      }
    }
docs: Prints a <code>ResultSet</code>.
  @param rs The <code>ResultSet</code> to print.
  @param out The <code>PrintStream</code> to write to.
  @throws SQLException If an error occurs while reading the
  <code>ResultSet</code>.