• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to copy a SQL result into a Map

 
Smiley Benson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have a problem with copying the results of my query code, producing four columns into a nested map - Map<String, Map<String, Map<String, Map<Integer, Map<String, Integer>>>>> puthere =
new Hashtable<String, Map<String, Map<String, Map<Integer, Map<String, Integer>>>>>();
 
Campbell Ritchie
Sheriff
Pie
Posts: 48938
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

You are setting up a Map to contain a Map to contain a Map to contain a Map?
You are getting 4 columns, and what you probably want is to get a Map where you have the PRIMARY KEY from the table/ResultSet/whatever as the "K" in the Map, and the remainder, probably put into a class designed to hold the remaining three columns, as the "E."
[ June 22, 2008: Message edited by: Campbell Ritchie ]
 
Smiley Benson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh yes! I see what you mean.
Run a query, get the first column, store the result in a map, then use that as key to get other values in another - say class or collection, where the Primary key equals the one in map.
But the problem is one is probably gonna end up with few thousand lines to complete! but would try it though.
Thanks
 
Campbell Ritchie
Sheriff
Pie
Posts: 48938
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More a case of create an object to hold all the results, and use that as the "V" in your Map. Use the primary key as the "E". And it will take several milliseconds to process your thousands of lines in Java!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic