Win a copy of Hello World this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Bear Bibeault
  • Liutauras Vilda
  • Devaka Cooray
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Displaying data

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am having a question regarding the display of data reteived from a database through a servlet.I am having all the rows of the database table displayed on the command prompt but with the spacing between columns in a row ripped apart because JDBC does that.Now I want to know if there is any method to keep the same spacing as it was before in the database table for all of the columns or use any other better spacing method so that now the display is better organised.To give you an idea of my table, it has got 5 columns with lengths 30,30,integer,20,500.Can anyone please give me an idea on how to solve this problem.
Thanking You,
Ashwin
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am not clear on what you want to acheive. If its as simple
as I think, its just display of data in tables. So your servlet
should send it to a html table.
I am not clear.......
regds.
- satya
 
Ashwin Tadepalli
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Satya,
Yes, we can definitely use a html table for that but i do not want to use that.I have already used that(html table) for displaying the result on the browser.Now I want another method of displaying the fetched data from the database in a command window(MS-DOS) after running that the java client program.So could you provide me of any alternate solution to this problem.
Thanking you,
Ashwin
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try XML (extensible markup language).
 
Ashwin Tadepalli
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Cindy,
I do not want to use XML and complicate things.Is there anyway I can do it using only java.Thanking You.
Ashwin
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing what you want is a method to return a Sting with a minimum width, taking an input String and padding with spaces as necessary. That's pretty simple to write:
<code><pre>
public class Test {

public static String padWithSpaces(String input, int size) {
StringBuffer sb = new StringBuffer(input);
while (sb.length() < size) {
sb.append(" ");
}
return sb.toString();
}

public static void main(String s[]) {
String[] a = {"red", "blue", "green", "yellow", "orange" };
String[] b = {"alpha", "beta", "gamma", "delta", "epsilon" };
String[] c = {"dog", "cat", "ferret", "parakeet", "lizard" };
for (int i = 0; i < 5; i++) {
System.out.print(padWithSpaces(a[i], 10));
System.out.print(padWithSpaces(b[i], 10));
System.out.print(padWithSpaces(c[i], 10));
System.out.println();
}
}
}
</pre></code>
And the output lines up nicely:
<code><pre>
red alpha dog
blue beta cat
green gamma ferret
yellow delta parakeet
orange epsilon lizard
</pre></code>
Of course, this in only useful if you have a fixed-width font. Like, say, at a DOS prompt. And of course you have to decide what to do if the input string is larger than the desired column width. This method simply returns the full input string in that case. If you want you can truncate the string instead; it's up to you.
 
Ashwin Tadepalli
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jim,
Thank you for reponding to my question and giving me your thoughtful opinion on it.What you meant was very close to what I have intended to do.I had to make modifications and make use of the padWithSpacesmethod.Anyway again thank you very,very much for helping me out of this problem.Bye.
Ashwin
 
Anderson gave himself the promotion. So I gave myself this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!