Skip to content

Instantly share code, notes, and snippets.

@schauder
Created September 20, 2023 13:22
Show Gist options
  • Save schauder/d20f07369c093d9a24e421ac9a1bd6d2 to your computer and use it in GitHub Desktop.
Save schauder/d20f07369c093d9a24e421ac9a1bd6d2 to your computer and use it in GitHub Desktop.
ResultSetExtractor for quickly logging a ResultSet
jdbc.query(sql, singletonMap("id", aggregate.id), new ResultSetExtractor<Object>() {
@Override
public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
int columns = rs.getMetaData().getColumnCount();
for (int i = 1; i <= columns; i++) {
if (i > 1) {
System.out.print(", ");
}
System.out.print(rs.getMetaData().getColumnLabel(i));
}
System.out.println();
while (rs.next()) {
for (int i = 1; i <= columns; i++) {
if (i > 1) {
System.out.print(", ");
}
System.out.print(rs.getString(i));
}
System.out.println();
}
return null;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment