Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Conversion From resultset to Map

 
Abiodun Adisa
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all, Please whats the easiest way to convert from Resultset into Map
 
Paul Clapham
Sheriff
Pie
Posts: 20776
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That depends on what data you want in the Map.
 
Abiodun Adisa
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Clapham:
That depends on what data you want in the Map.


Why would it depend on the type of value i want in the map. I already have a resultset that contains the results of a query i have executed and i want that value contained in a map
 
stu derby
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For each row in the resultset:
1. convert the row to an Object; only you can decide how to do that
2. pick a key for that Object; only you know what key might be appropriate
3. insert the Object into the map using the key
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can easily imagine a result set as a grid, or maybe a spreadsheet. One way to get that feeling in memory is an array of arrays, or a more flexible collection of collections. You can make a totally generic solution like this:

Now when you consume this thing you can get all the column information from the first object in the master list, then get one row of data from each of the subsequent objects in the master list.

I've done this for some generic tools, but wouldn't do it for a system-wide architecture. I'd much prefer to make an object for each unique query / set of result columns.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic