Java SQL ResultSet to toListMap(int limit, ResultSet rs)

Here you can find the source of toListMap(int limit, ResultSet rs)

Description

to List Map

License

Apache License

Declaration

public static List<Map> toListMap(int limit, ResultSet rs)
            throws SQLException 

Method Source Code

//package com.java2s;
//License from project: Apache 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> toListMap(int limit, ResultSet rs)
            throws SQLException {
        ResultSetMetaData rsmd = rs.getMetaData();
        int count = 0;
        List<Map> list = new ArrayList<Map>();
        while (rs.next()) {
            Map row = new HashMap();
            for (int i = 1; i <= rsmd.getColumnCount(); i++) {
                row.put(rsmd.getColumnName(i), rs.getObject(i));
            }//from ww  w .  ja  v  a 2s.co  m
            list.add(row);
            count++;
            if (count >= limit) {
                break;
            }
        }
        return list;
    }
}

Related

  1. resultSetToString(ResultSet resultSet)
  2. resultSetToXML(ResultSet rs)
  3. toArrayList(ResultSet rs)
  4. toAttributeMap(ResultSet resultSet)
  5. toJSONFromResultSet(ResultSet resultSet)
  6. toMap(final ResultSet resultSet)
  7. toMap(final ResultSet resultSet)
  8. toMapList(ResultSet rs)
  9. toMapOfLists(ResultSet rs)