Here you can find the source of getMap(ResultSet resultSet)
Parameter | Description |
---|---|
resultSet | The ResultSet to process. |
public static Map getMap(ResultSet resultSet) throws SQLException
//package com.java2s; // it under the terms of the GNU General Public License as published by import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; public class Main { /**//from w w w .jav a 2 s . co m * Returns next record of result set as a Map. * The keys of the map are the column names, * as returned by the metadata. * The values are the columns as Objects. * * @param resultSet The ResultSet to process. * @exception SQLException if an error occurs. */ public static Map getMap(ResultSet resultSet) throws SQLException { // Acquire resultSet MetaData ResultSetMetaData metaData = resultSet.getMetaData(); int cols = metaData.getColumnCount(); // Create hashmap, sized to number of columns HashMap row = new HashMap(cols, 1); // Transfer record into hashmap if (resultSet.next()) { for (int i = 1; i <= cols; i++) { row.put(metaData.getColumnName(i), resultSet.getObject(i)); } } // end while return ((Map) row); } }