List of utility methods to do SQL ResultSet to
Map | toAttributeMap(ResultSet resultSet) to Attribute Map return toAttributeMap(resultSet, null, true, null, null);
|
String | toJSONFromResultSet(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); ... |
List | toListMap(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; |
Map | toMap(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; |
HashMap | toMap(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; ... |
Object | toSingleResult(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()); ... |