Here you can find the source of toMapList(ResultSet rs)
public static List<Map<String, Object>> toMapList(ResultSet rs) throws java.sql.SQLException
//package com.java2s; /**/* w w w . j ava2 s .co m*/ * Copyright (C) 2016 - 2017 youtongluan. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class Main { public static List<Map<String, Object>> toMapList(ResultSet rs) throws java.sql.SQLException { List<Map<String, Object>> list = new ArrayList<>(); if (rs == null) { return list; } ResultSetMetaData md = rs.getMetaData(); int columnCount = md.getColumnCount(); Map<String, Object> rowData = new HashMap<>(); while (rs.next()) { rowData = new HashMap<>(columnCount); for (int i = 1; i <= columnCount; i++) { rowData.put(md.getColumnName(i), rs.getObject(i)); } list.add(rowData); } return list; } }