Created
August 29, 2014 07:01
-
-
Save zhouji/9adcf93fa6e85c74fe48 to your computer and use it in GitHub Desktop.
ResultSet to List<Map>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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