wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes JDBC result set - best way to store results? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

JDBC result set - best way to store results?

Shailan Mm
Greenhorn

Joined: Oct 06, 2004
Posts: 8
Hi

I was wondering what the common ways to store the results of a JDBC query were. I have recently migrated from Perl, and am used to storing the results in a hash. Is there a similar data structure that can easily handle the results of the query. I have tried HashMap, but cant figure out how to get a key to map to another HashMap internally without explicitly creating the internal HashMaps first.

E.g.
The query is something like this:
select animal, type, name from animals;

and the result set is:

Animal Type Name
dog husky Bella
dog poodle Alfie
cat manc Gus

I want the data structure to look like this:

dog => husky => Bella
poodle => Alfie
cat => manc => Gus


Alternatively, is there some better way to store the results rather than trying to duplicate Perl hashes?

Thank you
Shailan
Shailan Mm
Greenhorn

Joined: Oct 06, 2004
Posts: 8
To clarify (the formatting got messed up)

I want the data structure to have:

1) 2 top level keys - dog and cat
2) the 'dog' key pointing to another HashMap which itself has 2 keys - husky and poodle, with the value for husky being Bella and the value for poodle, Alfie
3) the cat key having a value Gus

Sorry to belabor the point, but the graphical representation i tried to give was not clear. It looked like I wanted to make poodle a top level key, which is not the case

Thanks
Shailan
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Shailan, please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place. Please continue any discussion of this topic here in the JDBC forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC result set - best way to store results?
 
Similar Threads
Copying parent class object into new subclass object
Generics extends keyword and getElement()
ways to store results from query?
Generics Question
Multiple set of data mapping