JDBC is Java’s database connectivity API. It can expose a ResultSet as a list of maps, letting downstream data-oriented code pass values along without immediately committing to concrete types. section 10.1
A practical JDBC-to-data flow is:
- Execute a database query and receive a ResultSet. section 10.1
- Read column labels and values through ResultSetMetaData and getObject. section 10.1
- Store each row in a Map<String, Object>, then pass the collection toward JSON serialization. section 10.1
Converting rows without elaborate mapping
A small conversion function loops through the ResultSet, uses each column label as a map key, obtains each value as an Object, and returns a list of maps. Type handling can wait until serialization. section 10.1
Listing 10.5 Converting a JDBC result set into a list of hash maps
List<Map<String, Object>> convertJDBCResultSetToListOfMaps(ResultSet rs) {
List<Map<String, Object>> listOfMaps =
new ArrayList<Map<String, Object>>();
ResultSetMetaData meta = rs.getMetaData();
while (rs.next()) {
Map map = new HashMap();
for (int i = 1; i <= meta.getColumnCount(); i++) {
String key = meta.getColumnLabel(i);
Object value = rs.getObject(i);
map.put(key, value);
}
listOfMaps.add(map);
}
return listOfMaps;
}
Inspect the complete ResultSet-to-list-of-maps implementation. section 10.1

