Here you can find the source of getRecordsFromResultSet(ResultSet rs)
Parameter | Description |
---|---|
conn | An existing SQL Connection |
fromSchema | The schema containing the table to perform the SELECT statement on. |
fromTable | The table to perform the SELECT statement on. |
whereParams | A map of column names to String values used to construct a WHERE clause. |
Parameter | Description |
---|---|
SQLException | If the query fails. |
public static List<Map<String, String>> getRecordsFromResultSet(ResultSet rs) throws SQLException
//package com.java2s; /*/* ww w .ja v a 2 s . com*/ Weave (Web-based Analysis and Visualization Environment) Copyright (C) 2008-2011 University of Massachusetts Lowell This file is a part of Weave. Weave is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License, Version 3, as published by the Free Software Foundation. Weave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Weave. If not, see <http://www.gnu.org/licenses/>. */ import java.sql.ResultSet; import java.sql.SQLException; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Vector; public class Main { /** * @param conn An existing SQL Connection * @param fromSchema The schema containing the table to perform the SELECT statement on. * @param fromTable The table to perform the SELECT statement on. * @param whereParams A map of column names to String values used to construct a WHERE clause. * @return The resulting rows returned by the query. * @throws SQLException If the query fails. */ public static List<Map<String, String>> getRecordsFromResultSet(ResultSet rs) throws SQLException { // list the column names in the result String[] columnNames = new String[rs.getMetaData().getColumnCount()]; for (int i = 0; i < columnNames.length; i++) columnNames[i] = rs.getMetaData().getColumnName(i + 1); // create a Map from each row List<Map<String, String>> records = new Vector<Map<String, String>>(); while (rs.next()) { Map<String, String> record = new HashMap<String, String>(columnNames.length); for (int i = 0; i < columnNames.length; i++) { String columnName = columnNames[i]; String columnValue = rs.getString(columnName); record.put(columnName, columnValue); } records.add(record); } return records; } }