aspose file tools*
The moose likes JDBC and the fly likes How to copy a SQL result into a Map Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to copy a SQL result into a Map" Watch "How to copy a SQL result into a Map" New topic
Author

How to copy a SQL result into a Map

Smiley Benson
Greenhorn

Joined: Jun 22, 2008
Posts: 2
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

Joined: Oct 13, 2005
Posts: 40038
    
  28
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

Joined: Jun 22, 2008
Posts: 2
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

Joined: Oct 13, 2005
Posts: 40038
    
  28
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to copy a SQL result into a Map