---
title: "ResultSet转换为List的方法 "
author: "hao861002"
date: "2009-04-11T20:39:28Z"
tags: []
slug: "resultset-list"
draft: false
lastmod: "2009-04-11T20:39:28Z"
id: 365722
url: "https://hao861002.iteye.com/blog/365722"
---

ResultSet转换为List的方法

private static List convertList(ResultSet rs) throws SQLException {

List list = new ArrayList();

ResultSetMetaData md = rs.getMetaData();

int columnCount = md.getColumnCount(); //Map rowData;

while (rs.next()) { //rowData = new HashMap(columnCount);

Map rowData = new HashMap();

for (int i = 1; i &lt;= columnCount; i++) {

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

}

 list.add(rowData);

} return list;

}