aspose file tools*
The moose likes JSP and the fly likes Creating a HTML table to display values from a database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Creating a HTML table to display values from a database" Watch "Creating a HTML table to display values from a database" New topic
Author

Creating a HTML table to display values from a database

Sridhar Venkataraman
Ranch Hand

Joined: May 22, 2006
Posts: 76
I have a database where I need to display as many rows in a HTML table as the maximum value in one of the columns in the corresponding table in a database.

For example, consider this bunch of data stored in the database:

1 | 1 | abc
1 | 2 | def
1 | 3 | ghi
2 | 1 | jkl
2 | 2 | mno
2 | 3 | pqr

Now, I need to create two rows (because the maximum value in the first column is 2) in the HTML table where I want to display this data. However, for every row which has the value 1 or 2, I need to create three columns (because there are three entries with the values 1 and 2 in the first column).

So the result (i.e. HTML table) rendered on the JSP page should be something like (consider that I'm displaying the last column):

abc | def | ghi
jkl | mno | pqr


How do I implement this in JSP, considering that I'm following an MVC architecture (no special frameworks like Struts and the like though)?

Thanks all for your inputs.

[ January 08, 2008: Message edited by: Sridhar Venkataraman ]

[ January 08, 2008: Message edited by: David O'Meara ]
[ January 08, 2008: Message edited by: Bear Bibeault ]
Pras Tiwari
Ranch Hand

Joined: Nov 07, 2005
Posts: 186
Considering this is your database table:-

1 | 1 | abc
1 | 2 | def
1 | 3 | ghi
2 | 1 | jkl
2 | 2 | mno
2 | 3 | pqr

Could you please mention/draw here the layout to be displayed in web page (2rows & 3 columns with above data) also? Because I am not sure what you want to be displayed exactly.


********Deserve Before You Desire********
Sridhar Venkataraman
Ranch Hand

Joined: May 22, 2006
Posts: 76
So the result (i.e. HTML table) rendered on the JSP page should be something like (consider that I'm displaying the last column):

abc | def | ghi
jkl | mno | pqr

Here...I had this in my first post.

Basically this comes from the fact that the first column has two distinct numnbers (1 and 2), and there are three instances where these numbers appear in the first column. So I need the output to display all the rows which have a value of 1,2....and so on in the same row on the HTML table.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Please EaseUp.

Dave
Sridhar Venkataraman
Ranch Hand

Joined: May 22, 2006
Posts: 76
Apologies...it's kind of a bad habit that I have
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

No problem
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating a HTML table to display values from a database
 
Similar Threads
Problem in regular expression for matching
how to split "abc-def - ghi-jkl"?
problem in writing Regular Expression
Parsing a String value in StoredProcedure???
Making a column invisible in a JTable