Example usage for org.springframework.jdbc.support JdbcUtils lookupColumnName

List of usage examples for org.springframework.jdbc.support JdbcUtils lookupColumnName

Introduction

In this page you can find the example usage for org.springframework.jdbc.support JdbcUtils lookupColumnName.

Prototype

public static String lookupColumnName(ResultSetMetaData resultSetMetaData, int columnIndex)
        throws SQLException 

Source Link

Document

Determine the column name to use.

Usage

From source file:org.tinygroup.tinydb.util.TinyBeanUtil.java

public static List<Field> getFieldsWithResultSet(ResultSet rs, BeanDbNameConverter converter)
        throws SQLException {
    ResultSetMetaData rsmd = rs.getMetaData();
    int columnCount = rsmd.getColumnCount();
    List<Field> fields = new ArrayList<Field>();
    Map<String, Integer> columnViewnum = new HashMap<String, Integer>();
    for (int index = 1; index <= columnCount; index++) {
        String columnName = JdbcUtils.lookupColumnName(rsmd, index);
        String propertyName = converter.dbFieldNameToPropertyName(columnName);
        String name = propertyName;
        if (!columnViewnum.containsKey(propertyName)) {
            columnViewnum.put(propertyName, 1);
        } else {//  w  w  w.  j  a  v a 2s . c  o m
            int number = columnViewnum.get(propertyName);
            name = propertyName + number;
            columnViewnum.put(propertyName, number++);
        }
        Field field = new Field();
        field.setName(name);
        field.setIndex(index);
        field.setPrecision(rsmd.getPrecision(index));
        field.setScale(rsmd.getScale(index));
        field.setType(rsmd.getColumnType(index));
        fields.add(field);
    }
    return fields;
}