Here you can find the source of executeQuery(String sql, Connection conn, List
public static List<Map<String, Object>> executeQuery(String sql, Connection conn, List<Object> param) throws SQLException
//package com.java2s; //License from project: Open Source License import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.ResultSetMetaData; 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<String, Object>> executeQuery(String sql, Connection conn, List<Object> param) throws SQLException { List<Map<String, Object>> data = new ArrayList<Map<String, Object>>(); PreparedStatement stmt = conn.prepareStatement(sql); if (param != null) { for (int i = 0; i < param.size(); i++) { stmt.setObject(i + 1, param.get(i)); }/*from ww w.j a va 2 s .co m*/ } ResultSet rs = stmt.executeQuery(); try { ResultSetMetaData rsmd = rs.getMetaData(); while (rs.next()) { Map<String, Object> row = new HashMap<String, Object>(); for (int i = 1; i <= rsmd.getColumnCount(); i++) { row.put(rsmd.getColumnName(i), rs.getObject(i) == null ? "" : rs.getObject(i)); } data.add(row); } } finally { rs.close(); stmt.close(); closeConnection(conn); } return data; } public static List<Map<String, Object>> executeQuery(String sql, Connection conn, List<Object> param, boolean b) throws SQLException { List<Map<String, Object>> data = new ArrayList<Map<String, Object>>(); PreparedStatement stmt = conn.prepareStatement(sql); if (param != null) { for (int i = 0; i < param.size(); i++) { stmt.setObject(i + 1, param.get(i)); } } ResultSet rs = stmt.executeQuery(); try { ResultSetMetaData rsmd = rs.getMetaData(); while (rs.next()) { Map<String, Object> row = new HashMap<String, Object>(); for (int i = 1; i <= rsmd.getColumnCount(); i++) { row.put(rsmd.getColumnName(i), rs.getObject(i) == null ? "" : rs.getObject(i)); } data.add(row); } } finally { rs.close(); stmt.close(); if (b) closeConnection(conn); } return data; } public static void closeConnection(Connection conn) throws SQLException { if (conn != null) { conn.rollback(); conn.close(); } } }