public static List resultSetToList(ResultSet rs) throws java.sql.SQLException {   
           
if (rs == null)   
               
return Collections.EMPTY_LIST;   
           ResultSetMetaData md 
= rs.getMetaData(); //得到结果集(rs)的结构信息,比如字段数、字段名等   
           int columnCount = md.getColumnCount(); //返回此 ResultSet 对象中的列数   
           List list = new ArrayList();   
           Map rowData 
= new HashMap();   
           
while (rs.next()) {   
            rowData 
= new HashMap(columnCount);   
            
for (int i = 1; i <= columnCount; i++) {   
                    rowData.put(md.getColumnName(i), rs.getObject(i));   
            }   
            list.add(rowData);   
            System.out.println(
"list:" + list.toString());   
           }   
           
return list;   
   }  

接着在其他方法里处理返回的List
List ls = resultSetToList(rs);   
Iterator it 
= ls.iterator();   
while(it.hasNext()) {   
    Map hm 
= (Map)it.next();   
    System.out.println(hm.get(
"字段名大写"));   
}  

相关文章:

  • 2022-01-20
  • 2022-12-23
  • 2021-06-16
  • 2022-02-09
  • 2022-12-23
  • 2021-12-15
  • 2022-12-23
猜你喜欢
  • 2021-09-07
  • 2022-12-23
  • 2021-08-26
  • 2021-11-03
相关资源
相似解决方案