609ppa
Last Updated: June 02, 2017
·
42.35K
· lukasz-madon
B2bc42f69510d6a1d2c9cde1c2214d24

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("");
   }
Say Thanks
Respond

3 Responses
Add your response

12651
Breaddays

Thank you! :D

over 1 year ago ·
17312
None

THX! If I delete the empty string, it doesnt work anymore, any idea why?

over 1 year ago ·
28585

Hi dear,
I am a java beginner student. This simple code to set to printing the result of ResultSet good. I have earlier try some code. That syntax is not working properly. Now when i uses this code my program working now. Thanks for your valuable sharing.

Thanks,

http://bit.ly/2kGE7G0

6 months ago ·