Java SQL ResultSet to convertResultSetToMap(final ResultSet rs)

Here you can find the source of convertResultSetToMap(final ResultSet rs)

Description

convert Result Set To Map

License

Open Source License

Declaration

private static Collection<Map<String, Object>> convertResultSetToMap(final ResultSet rs) 

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.Collection;
import java.util.HashMap;
import java.util.Map;

public class Main {
    private static Collection<Map<String, Object>> convertResultSetToMap(final ResultSet rs) {
        try {// w  w  w.  j a v  a2s .c  o  m
            ResultSetMetaData metaData = rs.getMetaData();
            int colum = metaData.getColumnCount();
            Collection<Map<String, Object>> collection = new ArrayList<Map<String, Object>>();
            Map<String, Object> row = null;
            while (rs.next()) {
                row = new HashMap<String, Object>();
                for (int i = 0; i < colum; i++)
                    row.put(metaData.getColumnName(i), rs.getObject(i));
                collection.add(row);
            }
            return collection;
        } catch (SQLException e) {
            return null;
        } finally {
            try {
                rs.close();
            } catch (SQLException e) {
            }
        }
    }
}

Related

  1. convert(int sqlType, String type, ResultSet rs, String name)
  2. convert(ResultSet rs)
  3. convertResultSetToJSON(ResultSet resultSet)
  4. convertToMap(Map metaData, ResultSet rs)
  5. resultSet2List(ResultSet rs)
  6. resultSet2Map(ResultSet rs)
  7. resultSetAsCSV(ResultSet rsh)