This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Hands On Software Engineering with Python and have Brian Allbey on-line!
See this thread for details.
Win a copy of Hands On Software Engineering with Python this week in the Jython/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
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

How to do looping in collection ?  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

My SQL returns the values as like below.


I'm getting the result and iterate the values to display.But in the last column need to display the values as different format.



Display format is...



How to append prizes 4 rows values in first row ? How to loop through here ?
Please help me.


 
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bob

Welcome to Java Ranch

If possible, change the DB table structure .. apply 1NF and 2NF to aggregate Prize columns into single row for any Student.
If it is not possible, then, you can define a Map with key as Student id (String type) and value as Set of Prizes [ Map<String,Set><String>].

While iterating through DB records,



now you have a map of Prizes with Student id as key. So at the end of iteration, you shall have a Set of Prize 1,2,3,4 for Student id 121.

~ abhay>
 
bob peter
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply.
How is this works ? Is this possible in 1.5 ? Is giving me an syntax error.
Map<String,Set><String> prizeMap = new HashMap<String, Set><String>();

Thanks
 
Marshal
Posts: 67191
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you are trying to accomplish, but the following is not valid syntax: Map<String,Set><String> prizeMap

Did you mean Map<String,Set<String>> prizeMap?
 
bob peter
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But HashMap won't support dublicate values or key. ? if adding more than one dublicate values , its going to overwrite...I want all values as like and only different is last column adding all rows values into one column.
 
Abhay Agarwal
Ranch Hand
Posts: 1376
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes , I meant Map<String,Set<String>> prizeMap
 
We cannot change unless we survive, but we will not survive unless we change. Evolving tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!