Java SQL ResultSet to resultSetParseVO(ResultSet rs, Class cls)

Here you can find the source of resultSetParseVO(ResultSet rs, Class cls)

Description

result Set Parse VO

License

Open Source License

Parameter

Parameter Description
rs a parameter
cls a parameter

Exception

Parameter Description
Exception an exception

Declaration

public static Object resultSetParseVO(ResultSet rs, Class<?> cls) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.Field;
import java.sql.ResultSet;

public class Main {
    /**//from   w w  w.  j  a v  a2 s .  c  o  m
     * 
     * @param rs
     * @param cls
     * @return
     * @throws Exception
     */
    public static Object resultSetParseVO(ResultSet rs, Class<?> cls) throws Exception {
        Object obj = cls.newInstance();
        Field[] fs = cls.getDeclaredFields();
        for (Field field : fs) {
            String name = field.getName();
            String value = rs.getString(rs.findColumn(name));
            field.set(obj, value);
        }
        return obj;
    }
}

Related

  1. convertToMap(Map metaData, ResultSet rs)
  2. resultSet2List(ResultSet rs)
  3. resultSet2Map(ResultSet rs)
  4. resultSetAsCSV(ResultSet rsh)
  5. resultSetCurrentData(ResultSet rs)
  6. resultSetToArrayList(ResultSet rs)
  7. resultSetToHtmlTable(java.sql.ResultSet rs)
  8. resultSetToMap(Map mappedValues, java.sql.ResultSet rs, int key, int value)
  9. resultSetToMap(Map mappedValues, ResultSet rs)