重温Java持久化(三)

2014-11-24 08:36:39 · 作者: · 浏览: 15
= params[i];
if (obj != null)
str = str.replace("{" + i + "}", obj.toString());
}
return str;
}
public static List buildEntities(RowSet rs, Class clazz, List allFields) throws SQLException, InstantiationException, IllegalAccessException {
List listCols = getRowSetColName(rs);
List list = new ArrayList();
while (rs.next()) {
List values = new ArrayList();
for (String key : listCols) {
values.add(rs.getObject(key));
}
Object obj = ClassUtil.buildProperties(clazz, allFields, values);
list.add(obj);
}
return list;
}
public static List getRowSetColName(RowSet rs) throws SQLException {
List collist = new ArrayList();
for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
collist.add(rs.getMetaData().getColumnName(i + 1).toUpperCase());
}
return collist;
}
}
作者:jrunner