Java SQL ResultSet loadListMap(final ResultSet rs)

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

Description

load List Map

License

Open Source License

Declaration

public static List<Map<?, ?>> loadListMap(final ResultSet rs)
        throws SQLException, IllegalAccessException, InvocationTargetException 

Method Source Code

//package com.java2s;
/******************************************************************************
 * Product: ADempiereLBR - ADempiere Localization Brazil                      *
 * This program is free software; you can redistribute it and/or modify it    *
 * under the terms version 2 of the GNU General Public License as published   *
 * by the Free Software Foundation. This program 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 this program; if not, write to the Free Software Foundation, Inc.,    *
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.                     *
 *****************************************************************************/

import java.lang.reflect.InvocationTargetException;

import java.sql.ResultSet;
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<?, ?>> loadListMap(final ResultSet rs)
            throws SQLException, IllegalAccessException, InvocationTargetException {

        List<Map<?, ?>> list = new ArrayList<Map<?, ?>>();

        while (rs.next()) {
            list.add(loadMap(rs));//from   w ww .  j  ava2  s  . c o m
        }

        return list;
    }

    public static Map<String, Object> loadMap(final ResultSet rs)
            throws SQLException, IllegalAccessException, InvocationTargetException {

        int columnCount = rs.getMetaData().getColumnCount();
        String columnName = null;
        Object columnValue = null;
        Map<String, Object> fieldValue = new HashMap<String, Object>();

        for (int column = 1; column <= columnCount; column++) {
            columnName = rs.getMetaData().getColumnName(column);
            columnValue = rs.getObject(column);
            fieldValue.put(columnName, columnValue);
        }

        return fieldValue;
    }
}

Related

  1. hasGeometryField(ResultSet resultSet)
  2. isNull(ResultSet rs, String name)
  3. isResultEmpty(ResultSet theResult)
  4. isReturnsInvalidResultSetException(SQLException se)
  5. isSupportedResultSetType(Connection connection, int resultSetType)
  6. logCurrentResultSetRow(Log log, String msg, ResultSet rs)
  7. mapResultSet(ResultSet set)
  8. moveToPageNo(ResultSet rs, int pageNo, int pageSize)
  9. parseSqlResultToListMap(ResultSet rs)