wood burning stoves 2.0*
The moose likes Java in General and the fly likes Displaying data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Displaying data " Watch "Displaying data " New topic
Author

Displaying data

Ashwin Tadepalli
Greenhorn

Joined: Feb 01, 2001
Posts: 27
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

Joined: Jun 03, 2000
Posts: 5040

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

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Ashwin Tadepalli
Greenhorn

Joined: Feb 01, 2001
Posts: 27
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

Joined: Sep 29, 2000
Posts: 8521
Try XML (extensible markup language).


"JavaRanch, where the deer and the Certified play" - David O'Meara
Ashwin Tadepalli
Greenhorn

Joined: Feb 01, 2001
Posts: 27
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

Joined: Jan 30, 2000
Posts: 18671
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.

"I'm not back." - Bill Harding, Twister
Ashwin Tadepalli
Greenhorn

Joined: Feb 01, 2001
Posts: 27
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
 
subject: Displaying data
 
Similar Threads
pictures in a jsp
Resultset from Action class to JSP ?
Is it possible to give row names and column names for a JTable
Interchanging Database columns as rows while displaying in a JTable
Is there a way for updating JTree and JTable with a same model?