日期:2014-05-20  浏览次数:20702 次

结果集转换成数组或者COLLECTIONS有几种方法?在线等
RT  
个人对结果集的处理有些疑惑!

------解决方案--------------------
关于apache提供的这个工具类位于common子项目下的BeanUtils包中


具体的你可以看
http://jakarta.apache.org/commons/beanutils/


用这个包中的RowSetDynaClass类


例子:
Connection conn = ...; // Acquire connection from pool
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery( "SELECT ... ");
RowSetDynaClass rsdc = new RowSetDynaClass(rs);
rs.close();
stmt.close();
...; // Return connection to pool
List rows = rsdc.getRows();
...; // Process the rows as desired


返回的List对象是一个集合,其中的每个对象都是DynaBean对象(也位于这个包下)。


具体的RowSetDynaClass 和DynaBean对象的使用方法,你可以看我上面的那个联接,有详细的说明和API文档。