Search code examples
javajdbcstring-formatting

How to output Database Results in given format using Java


I was trying to print out the table data in a particular format like the one I have attached below.


Solution

  • System.out.printf("%10s %10s %10s %10s %10s \n", "STUDENT ID", "EMAIL ID", "NAME", "AGE", "GRADE");
    

    Increase the x in %xsto increase the spaces. Apply loop for the hyphens (-) and loop over your result from db in a similar way to the snippet above.