Java SQL ResultSet to toMap(final ResultSet resultSet)

Here you can find the source of toMap(final ResultSet resultSet)

Description

ResultSet2Map

License

Open Source License

Parameter

Parameter Description
resultSet a parameter

Exception

Parameter Description
Exception an exception

Declaration

public static Map<String, String> toMap(final ResultSet resultSet) throws SQLException 

Method Source Code

//package com.java2s;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Map;

import com.google.common.collect.Maps;

public class Main {
    /**/*from  w ww  . j  av  a2  s . c o  m*/
     * ResultSet2Map
     * @param resultSet
     * @return
     * @throws Exception
     */
    public static Map<String, String> toMap(final ResultSet resultSet) throws SQLException {

        final Map<String, String> m = Maps.newHashMap();
        final ResultSetMetaData metadata = resultSet.getMetaData();

        for (int i = 0; i < metadata.getColumnCount(); i++) {
            final String key = metadata.getColumnName(i + 1);
            m.put(key, resultSet.getString(key));
        }
        return m;
    }
}

Related

  1. toArrayList(ResultSet rs)
  2. toAttributeMap(ResultSet resultSet)
  3. toJSONFromResultSet(ResultSet resultSet)
  4. toListMap(int limit, ResultSet rs)
  5. toMap(final ResultSet resultSet)
  6. toMapList(ResultSet rs)
  7. toMapOfLists(ResultSet rs)
  8. toObjectArray(ResultSet resultSet)
  9. toSingleResult(ResultSet rs)