code: private String[] getColumnNames(ResultSetMetaData rsmd) throws Exception {
          ArrayList<String> names = new ArrayList<String>();
  
          // Get result set meta data
          int numColumns = rsmd.getColumnCount();
  
          // Get the column names; column indices start from 1
          for (int i = 1; i < numColumns + 1; i++) {
              String columnName = rsmd.getColumnName(i);
  
              names.add(columnName);
          }
  
          return names.toArray(new String[0]);
      }
docs: Gets all of the column names for a result meta data
  
  @param rsmd Resultset metadata
  @return Array of column names
  @throws Exception exception