Skip to content

Instantly share code, notes, and snippets.

@zhouji
Created August 29, 2014 07:01
Show Gist options
  • Save zhouji/9adcf93fa6e85c74fe48 to your computer and use it in GitHub Desktop.
Save zhouji/9adcf93fa6e85c74fe48 to your computer and use it in GitHub Desktop.
ResultSet to List<Map>
public static List<Map<String,String>> convert(ResultSet resultSet) throws SQLException {
List<Map<String,String>> rows = new ArrayList<>();
while (resultSet.next()) {
int total_rows = resultSet.getMetaData().getColumnCount();
Map<String,String> row = new HashMap<>();
for (int i = 0; i < total_rows; i++) {
row.put(resultSet.getMetaData().getColumnLabel(i + 1).toLowerCase(), resultSet.getObject(i + 1).toString());
}
rows.add(row);
}
return rows;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment