This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying data

 
Ashwin Tadepalli
Greenhorn
Posts: 27
  • 0
  • 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
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • 0
  • 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
  • 0
  • 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
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try XML (extensible markup language).
 
Ashwin Tadepalli
Greenhorn
Posts: 27
  • 0
  • 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
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • 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
  • 0
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic