Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6651157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:58:37+00:00 2026-05-26T00:58:37+00:00

I got everything working and it prints the right result with header (column name)

  • 0

I got everything working and it prints the right result with header (column name) and value. However I wanted to change a plain and unorganized result into a really nice output table format just like MySql table result with dash lines from query. How do I do that?

Statement statement = conn.createStatement();
ResultSet rs = statement.executeQuery("SELECT * FROM quarter");
ResultSetMetaData rsMetaData = rs.getMetaData();
int numberOfColumns = rsMetaData.getColumnCount();
for(int i = 1; i <= numberOfColumns; i++)
{
    System.out.print(rsMetaData.getColumnLabel(i) + " ");
}
System.out.println();
while (rs.next())
{
    for(int e = 1; e <= rsMetaData.getColumnCount(); e++)
    {
        System.out.print(rs.getString(e) + " ");
    }
    System.out.println();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:58:38+00:00Added an answer on May 26, 2026 at 12:58 am

    You can use String.format() method with appropriate format string.

    For instance,

    StringBuilder sb=new StringBuilder();
    
    for(int i = 1; i <= numberOfColumns; i++)
    {
        sb.append(String.format("| %-10s",rsMetaData.getColumnLabel(i)));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a module which serializes others and I've got everything working only I'm
Update and Solution I finally got everything working after 1. Uninstalling everything ruby-related in
I'm implementing a java SAX parser in my Android app. I've got everything working,
I've got everything working with ferret and acts_as_ferret for development (or localhost DRb), but
I'm working with the Google Maps Geocoder. I've got everything working fine, but I
I'm building a web server to host multiple websites. I got everything working except
ok i got everything working. the texture only applys for two sides only of
I had started the Rails app yesterday and got everything working. Then today I
I am trying to setup github to websever deployment automation. I've got everything working
Boy, I've got everything down-pat save the word referencing. The game crashes because of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.