All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sf.database.jdbc.rowmapper.MapRowMapper Maven / Gradle / Ivy

The newest version!
package sf.database.jdbc.rowmapper;

import sf.spring.util.LinkedCaseInsensitiveMap;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Map;

/**
 * 结果集转为Map
 */
public class MapRowMapper implements RowMapper> {

    @Override
    public Map handle(ResultSet rs, ResultSetMetaData rsmd, int rowNum) throws SQLException {
        Map result = new LinkedCaseInsensitiveMap<>();
        int cols = rsmd.getColumnCount();

        for (int i = 1; i <= cols; i++) {
            String columnName = rsmd.getColumnLabel(i);
            if (columnName == null || columnName.length() == 0) {
                columnName = rsmd.getColumnName(i);
            }
            result.put(columnName, rs.getObject(i));
        }

        return result;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy