Skip to content

Instantly share code, notes, and snippets.

@rnestertsov
Created February 4, 2019 08:53
Show Gist options
  • Select an option

  • Save rnestertsov/70746d12f09739a06d26ebc747a933b0 to your computer and use it in GitHub Desktop.

Select an option

Save rnestertsov/70746d12f09739a06d26ebc747a933b0 to your computer and use it in GitHub Desktop.
Print JDBC result set
private static void printResults(ResultSet rs) throws SQLException {
ResultSetMetaData rsMetadata = rs.getMetaData();
for (int i=1; i<=rsMetadata.getColumnCount(); i++) {
System.out.printf("%-15s | ", rsMetadata.getColumnName(i));
}
System.out.printf("\n");
while (rs.next()) {
for (int i=1; i<=rsMetadata.getColumnCount(); i++) {
System.out.printf("%-15s | ", rs.getString(i));
}
System.out.printf("\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment