Java SQL ResultSet Read getList(ResultSet rs)

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

Description

get List

License

Open Source License

Declaration

public static List<Map<String, String>> getList(ResultSet rs) throws SQLException 

Method Source Code


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

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 {
    public static List<Map<String, String>> getList(ResultSet rs) throws SQLException {
        if (rs == null) {
            return null;
        }// ww  w.ja v a  2  s .  co  m
        ResultSetMetaData md = rs.getMetaData();
        int columns = md.getColumnCount();
        ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>(50);
        while (rs.next()) {
            //MappedData row = new MappedData();
            HashMap<String, String> row = new HashMap<String, String>(columns);
            for (int i = 1; i <= columns; ++i) {
                String columnName = md.getColumnName(i);
                String columnVal = String.valueOf(rs.getObject(i));
                row.put(columnName, columnVal);
            }
            list.add(row);
        }
        return list;
    }
}

Related

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