code: public static String[] extractColumnLabels(ResultSet rs) throws SQLException {
          ResultSetMetaData rsmd = rs.getMetaData();
          int numColumns = rsmd.getColumnCount();
          String[] colLabels = new String[numColumns];
          for (int i = 1; i <= numColumns; i++) {
              colLabels[i - 1] = rsmd.getColumnLabel(i);
              if (colLabels[i - 1] == null) {
                  colLabels[i - 1] = rsmd.getColumnName(i);
              }
          }
          return colLabels;
      }
docs: Extract column label/name from a {@link ResultSet}.
  
  @param rs
  @return
  @throws SQLException