Java Utililty Methods SQL ResultSet Read

List of utility methods to do SQL ResultSet Read

Description

The list of methods to do SQL ResultSet Read are organized into topic(s).

Method

ArrayList>getListMapFromResultSet(ResultSet rs)
get List Map From Result Set
ArrayList<Map<String, String>> myList = new ArrayList<Map<String, String>>();
try {
    while (rs.next()) {
        Map<String, String> map = new HashMap<String, String>();
        ResultSetMetaData rsmd = rs.getMetaData();
        int numColumns = rsmd.getColumnCount();
        for (int i = 1; i < numColumns + 1; i++) {
            String columnName = rsmd.getColumnName(i);
...
LocalDategetLocalDate(ResultSet res, String name)
get Local Date
return LocalDate.parse(res.getString(name), tarmedFormatter);
LocalDategetLocalDate(ResultSet rs, String columnName)
Get LocalDate instance from the ResultSet rs with columnName
Date sqlDate = rs.getDate(columnName);
return sqlDate == null ? null : sqlDate.toLocalDate();
MapgetMap(ResultSet resultSet)
get Map
Map<String, Object> valueMap = new HashMap<String, Object>();
try {
    ResultSetMetaData metaData = resultSet.getMetaData();
    int columnCount = metaData.getColumnCount();
    for (int j = 1; j <= columnCount; j++) {
        valueMap.put(metaData.getColumnLabel(j), resultSet.getObject(j));
} catch (SQLException e) {
...
MapgetMap(ResultSet resultSet)
Returns next record of result set as a Map.
ResultSetMetaData metaData = resultSet.getMetaData();
int cols = metaData.getColumnCount();
HashMap row = new HashMap(cols, 1);
if (resultSet.next()) {
    for (int i = 1; i <= cols; i++) {
        row.put(metaData.getColumnName(i), resultSet.getObject(i));
return ((Map) row);
MapgetMap(ResultSet rs, ResultSetMetaData metaData, int cols_len)
get Map
Map<String, Object> map = new LinkedHashMap<String, Object>();
for (int i = 0; i < cols_len; i++) {
    String cols_name = metaData.getColumnLabel(i + 1);
    Object cols_value = getValueByObjectType(metaData, rs, i);
    map.put(cols_name, cols_value);
return map;
ResultSetMetaDatagetMetaData(ResultSet rs)
get Meta Data
ResultSetMetaData rsmd = rs.getMetaData();
return rsmd;
TgetNullable(final ResultSet resultSet, final T value)
Returns the given value or null if the last column lookup resulted in a null value.
return resultSet.wasNull() ? null : value;
BooleangetNullableBooleanFromResultSet(ResultSet rset, Enum field)
get Nullable Boolean From Result Set
return getNullableBooleanFromResultSet(rset, field.name());
BytegetNullableByte(ResultSet resultSet, String columnLabel)
Returns the value of the specified column from the ResultSet or null if the value is nullable and was null.
byte value = resultSet.getByte(columnLabel);
return resultSet.wasNull() ? null : value;