Java Utililty Methods SQL ResultSet to

List of utility methods to do SQL ResultSet to

Description

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

Method

MaptoAttributeMap(ResultSet resultSet)
to Attribute Map
return toAttributeMap(resultSet, null, true, null, null);
StringtoJSONFromResultSet(ResultSet resultSet)
to JSON From Result Set
StringBuilder builder = new StringBuilder();
ResultSetMetaData metadata = resultSet.getMetaData();
int colCount = metadata.getColumnCount();
builder.append("{");
for (int i = 1; i <= colCount; i++) {
    if (i >= 2)
        builder.append(",");
    Object value = resultSet.getObject(i);
...
ListtoListMap(int limit, ResultSet rs)
to List Map
ResultSetMetaData rsmd = rs.getMetaData();
int count = 0;
List<Map> list = new ArrayList<Map>();
while (rs.next()) {
    Map row = new HashMap();
    for (int i = 1; i <= rsmd.getColumnCount(); i++) {
        row.put(rsmd.getColumnName(i), rs.getObject(i));
    list.add(row);
    count++;
    if (count >= limit) {
        break;
return list;
MaptoMap(final ResultSet resultSet)
ResultSet2Map
final Map<String, String> m = Maps.newHashMap();
final ResultSetMetaData metadata = resultSet.getMetaData();
for (int i = 0; i < metadata.getColumnCount(); i++) {
    final String key = metadata.getColumnName(i + 1);
    m.put(key, resultSet.getString(key));
return m;
HashMaptoMap(final ResultSet resultSet)
to Map
final HashMap properties = new HashMap();
final ResultSetMetaData metaData = resultSet.getMetaData();
final int cols = metaData.getColumnCount();
while (resultSet.next()) {
    for (int i = 1; i <= cols; i++) {
        properties.put(metaData.getColumnName(i), resultSet.getString(i));
return (properties);
List>toMapList(ResultSet rs)
to Map List
List<Map<String, Object>> list = new ArrayList<>();
if (rs == null) {
    return list;
ResultSetMetaData md = rs.getMetaData();
int columnCount = md.getColumnCount();
Map<String, Object> rowData = new HashMap<>();
while (rs.next()) {
...
Map>toMapOfLists(ResultSet rs)
to Map Of Lists
Map<String, List<Object>> result = new HashMap<String, List<Object>>(128);
ResultSetMetaData header = rs.getMetaData();
for (int ii = 1; ii <= header.getColumnCount(); ii++)
    result.put(header.getColumnName(ii), new ArrayList<Object>());
while (rs.next()) {
    int ii = 1;
    while (ii <= header.getColumnCount()) {
        result.get(header.getColumnName(ii)).add(rs.getObject(ii));
...
Object[]toObjectArray(ResultSet resultSet)
to Object Array
ResultSetMetaData rsmd = resultSet.getMetaData();
int count = rsmd.getColumnCount();
Object[] result = new Object[count];
for (int colCursor = 1; colCursor <= count; colCursor++) {
    Object obj = resultSet.getObject(colCursor);
    result[colCursor - 1] = obj;
return result;
...
ObjecttoSingleResult(ResultSet rs)
to Single Result
Object result = null;
try {
    while (rs.next()) {
        result = rs.getObject(1);
        break;
} catch (Exception e) {
    throw new RuntimeException(e.getMessage());
...