Here you can find the source of queryObjectList(Connection con, String sql, Class
public static <T> List<T> queryObjectList(Connection con, String sql, Class<T> objClass) throws SQLException, InstantiationException, IllegalAccessException
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Constructor; import java.sql.*; import java.util.*; public class Main { public static <T> List<T> queryObjectList(Connection con, String sql, Class<T> objClass) throws SQLException, InstantiationException, IllegalAccessException { List<T> lists = new ArrayList<T>(); Statement stmt = null;/*from w ww . j a v a2s. com*/ ResultSet rs = null; try { stmt = con.createStatement(); rs = stmt.executeQuery(sql); label: while (null != rs && rs.next()) { Constructor<?>[] constor = objClass.getConstructors(); for (Constructor<?> c : constor) { Object value = rs.getObject(1); try { lists.add((T) c.newInstance(value)); continue label; } catch (Exception e) { } } } } finally { if (null != rs) rs.close(); if (null != stmt) stmt.close(); } return lists; } public static <T> List<T> queryObjectList(Connection con, String sql, Class<T> objClass, Object... params) throws SQLException, InstantiationException, IllegalAccessException { List<T> lists = new ArrayList<T>(); PreparedStatement preStmt = null; ResultSet rs = null; try { preStmt = con.prepareStatement(sql); for (int i = 0; i < params.length; i++) preStmt.setObject(i + 1, params[i]); rs = preStmt.executeQuery(); label: while (null != rs && rs.next()) { Constructor<?>[] constor = objClass.getConstructors(); for (Constructor<?> c : constor) { String value = rs.getObject(1).toString(); try { T t = (T) c.newInstance(value); lists.add(t); continue label; } catch (Exception e) { } } } } finally { if (null != rs) rs.close(); if (null != preStmt) preStmt.close(); } return lists; } }