public class DBResultToMapList { //根据结果封装成haspMap对象列表 public static List<HashMap<String, String>> getDBResultToMapList(ResultSet resultSet) { List<HashMap<String, String>> list = new ArrayList<>(); if (null != resultSet) { while (true) { try { if (!resultSet.next()) break; try { ResultSetMetaData metaData = resultSet.getMetaData(); int columnCount = metaData.getColumnCount(); HashMap<String, String> hashMap = new HashMap<>(); for (int i = 1; i < columnCount + 1; i++) { hashMap.put(metaData.getColumnName(i), resultSet.getString(metaData.getColumnName(i))); } list.add(hashMap); } catch (SQLException e) { e.printStackTrace(); } } catch (SQLException e) { e.printStackTrace(); } } } return list; } }
数据库查询结果转map
最新推荐文章于 2023-02-16 11:57:53 发布