Java SQL ResultSet Read getListMapFromResultSet(ResultSet rs)

Here you can find the source of getListMapFromResultSet(ResultSet rs)

Description

get List Map From Result Set

License

Open Source License

Declaration

public static ArrayList<Map<String, String>> getListMapFromResultSet(ResultSet rs) 

Method Source Code

//package com.java2s;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;

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

public class Main {
    public static ArrayList<Map<String, String>> getListMapFromResultSet(ResultSet rs) {

        ArrayList<Map<String, String>> myList = new ArrayList<Map<String, String>>();

        try {//  w  w  w .  j  a  v  a 2  s. com
            while (rs.next()) {
                Map<String, String> map = new HashMap<String, String>();
                ResultSetMetaData rsmd = rs.getMetaData();
                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);
                    String columnValue = rs.getString(columnName);
                    map.put(columnName, columnValue);
                }

                myList.add(map);
            }
        } catch (Exception e) {
            throw new RuntimeException("Unable to get data for execution", e);
        }

        return myList;
    }
}

Related

  1. getId(ResultSet key)
  2. getIndex(ResultSet rs, int index)
  3. getList(ResultSet resultSet, String columnLabel, Class clazz)
  4. getList(ResultSet rs)
  5. getListFromRS(Class clazz, ResultSet rs)
  6. getLocalDate(ResultSet res, String name)
  7. getLocalDate(ResultSet rs, String columnName)
  8. getMap(ResultSet resultSet)
  9. getMap(ResultSet resultSet)