丶子非鱼
2017-05-24 20:24
public List<Map<String, Object>> findResult(String sql, List<?> params) throws SQLException { List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); int index = 1; pstmt = connection.prepareStatement(sql); if (params != null && !params.isEmpty()) { for (int i = 0; i < params.size(); i++) { pstmt.setObject(index++, params.get(i)); } } resultSet = pstmt.executeQuery(); //getMetaData()获取结果集的所有字段的描述 ResultSetMetaData metaData = resultSet.getMetaData(); //得到数据集的列数 int cols_len = metaData.getColumnCount(); while (resultSet.next()) { Map<String, Object> map = new HashMap<String, Object>(); for (int i = 0; i < cols_len; i++) { String cols_name = metaData.getColumnName(i + 1); Object cols_value = resultSet.getObject(cols_name); if (cols_value == null) { cols_value = ""; } map.put(cols_name, cols_value); } list.add(map); } return list; }
获取数据结果集 (回答错了不要怪我,我是小白!)
获取数据结果集 (回答错了不要怪我,我是小白!)
Java 分页原理与实践(上)
65018 学习 · 147 问题
相似问题