• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

displaying results in a form

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a jsp which displays items available in the database in groups of their category ordered by catageory name. Each category is to be in a table with heading of the category name in a bigger font. Items belonging to that category will follow in the table in a smaller font having other columns like itemId, an image thumbnail, description etc. Next table will have the next category and items of that category.

I have two tables in the database - an ITEM table which has a referential integrity with CATEGORY table on category_id. CATEGROY table will have the categoryId and category_name columns. category_name is what is to be displayed as the heading for each table in the form.

I have a bean which will have all these columns as fields. I query the database and populate the bean with the results from database. Now, I am at a loss on how to write the code for jsp. I am having an idea that I should have a for loop for each category under which there will be another for loop for items of that category but how do I get the results in the format of category and items of that category?

I wrote the sql for getting the itmes and categoris like this....


select itemid, image, description, category_id, category_name from ITEMS A, CATEGORY B where A.category_id = B.category_id order by category_name.
I can populate the beans from teh resultset but I am at a loss on how to organise the results in proper java collections objects for me to be able to use them in the jsp.

Request experienced people to throw some light.

Thanks very much for reading my lengthy post and thanks very much in advance for your ideas.

Vasuma
 
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by vasuma patel:

I can populate the beans from teh resultset but I am at a loss on how to organise the results in proper java collections objects for me to be able to use them in the jsp.



Store ResultSet in ArrayList or Vector
 
vasuma patel
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am thinking of writing a SQL where I group the results by category_id and have the count(items). This will be my outer loop. I will loop for count no. of times in each category to get items ( another database call) and store them in a map ( category_id is the key and beans of the items in each category in an arraylist). Does it make sense?
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vasuma,
Yes, a Map makes sense if you will search by category id. If you want the list ordered by something else, you wouldn't use a map though.
 
These are the worst of times and these are the best of times. And this is the best tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic