阅读背景:

如何使用java从“Class.forName(name).newInstance()”获取当前字符串

来源:互联网 

this is my code :

这是我的代码:

public static List populate(ResultSet rs, Class clazz) throws Exception {

        ResultSetMetaData metaData = rs.getMetaData(); 

        int colCount = metaData.getColumnCount(); 

        List ret = new ArrayList(); 

        Field[] fields = clazz.getDeclaredFields(); 

        while (rs.next()) {
            Object newInstance = clazz.newInstance(); 



            for (int i = 1; i <= colCount; i++) { 
                try {
                    Object value = rs.getObject(i);

                    for (int j = 0; j < fields.length; j++) {
                        Field f = fields[j];
                        if (f.getName().replaceAll("_", "").equalsIgnoreCase(
                                metaData.getColumnName(i).replaceAll("_", ""))) {
                            BeanUtils.copyProperty(newInstance, f.getName(),
                                    value);
                        }
                    }
                } catch (Exception e) {

                    e.printStackTrace();
                }
            }
            ret.add(newInstance);
        }
        rs.close();
        return ret;
    }
public static Lis



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: