Printing the result of ResultSet
Sample code for printing java.sql.ResultSet
ResultSet rs = statement.executeQuery();
ResultSetMetaData rsmd = rs.getMetaData();
System.out.println("querying SELECT * FROM XXX");
int columnsNumber = rsmd.getColumnCount();
while (rs.next()) {
for (int i = 1; i <= columnsNumber; i++) {
if (i > 1) System.out.print(", ");
String columnValue = rs.getString(i);
System.out.print(columnValue + " " + rsmd.getColumnName(i));
}
System.out.println("");
}
Written by lukas
Related protips
2 Responses
Thank you! :D
over 1 year ago
·
THX! If I delete the empty string, it doesnt work anymore, any idea why?
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Jdbc
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#