1. 将JDBC ResultSet结果集转成List

public static List ResultSetToList(ResultSet rs) {

        try {

            ResultSetMetaData md = rs.getMetaData();    // 获得结果集结构信息(字段数、字段名等)

            int columnCount = md.getColumnCount();

            List list = new ArrayList();

            while (rs.next()) {

                Map rowData = new HashMap();

                for (int i = 1; i <= columnCount; i++) {

                    rowData.put(md.getColumnName(i), rs.getObject(i));

                }

                list.add(rowData);

            }

            return list;

        } catch (SQLException e) {

            e.printStackTrace();

        }

        return null;

    }

你可能感兴趣的:(ResultSet)