Java SQL ResultSet Read getAllValueMaps(ResultSet input)

Here you can find the source of getAllValueMaps(ResultSet input)

Description

Get a List of Maps containing the rows of the ResultSet with a matching valid date information.

License

Open Source License

Parameter

Parameter Description
input a parameter
validFrom a parameter

Exception

Parameter Description
SQLException an exception

Declaration

public static List<Map<String, String>> getAllValueMaps(ResultSet input) throws SQLException, IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.HashMap;

import java.util.List;
import java.util.Map;

public class Main {
    /**/*from  w  ww .j a  va  2 s.  c o m*/
     * Get a List of Maps containing the rows of the ResultSet with a matching valid date
     * information. This is needed as we can not make constraints on a date represented as string in
     * the db.
     * 
     * @param input
     * @param validFrom
     * @return
     * @throws SQLException
     */
    public static List<Map<String, String>> getAllValueMaps(ResultSet input) throws SQLException, IOException {
        List<Map<String, String>> ret = new ArrayList<Map<String, String>>();

        // build list of column names
        ArrayList<String> headers = new ArrayList<String>();
        ResultSetMetaData meta = input.getMetaData();
        int metaLength = meta.getColumnCount();
        for (int i = 1; i <= metaLength; i++) {
            headers.add(meta.getColumnName(i));
        }

        // find rows with matching valid date information
        while (input.next()) {
            HashMap<String, String> valuesMap = new HashMap<String, String>();
            // put all the columns with values into valuesMap
            for (String columnName : headers) {
                String value = input.getString(columnName);
                valuesMap.put(columnName, value);
            }
            // add map to list of matching maps
            ret.add(valuesMap);
        }
        return ret;
    }
}

Related

  1. get(ResultSet rs, String name)
  2. getAllColumnNames(ResultSet rs)
  3. getAllColumnNamesFromResultSet(ResultSet set)
  4. getAllData(ResultSet rs)
  5. getAllRow(ResultSet rs)
  6. getArray(ResultSet resultSet, String columnLabel, Class clazz)
  7. getArray(ResultSet rs, int index)
  8. getArray(ResultSet rs, String columnName, Class cls)
  9. getArrayAsSet(ResultSet rs, String columnLabel)