日期:2014-05-16  浏览次数:20411 次

用Map封装数据库查询结果集

用Map封装数据库查询结果集

List list=new ArrayList();

ResultSetMetaData md=rs.getMetaData();
int columnCount=md.getColumnCount();

Map map = null;   
while (rs.next()) {   
	map = new HashMap(columnCount);   
	for (int i = 1; i <= columnCount; i++) {   
		map.put(md.getColumnName(i), rs.getObject(i));   
	}   
	list.add(map); 
}

??