This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes A Design Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "A Design Question" Watch "A Design Question" New topic
Author

A Design Question

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hello All,
I am in a process of writing a java program which queries a database. I am retreiving all kinds of information and then I have to display it as a report. My concern is that that I have to make a HashMap inside a HashMap. What I mean is
HashMap1
-------------
Keys | Values
--------------
Unique| HashMap2
Unique| HashMap3
.
.
.
.
The HashMap2 also have there unique keys and values.
Is there a better solution than the soln I presented??
Thanks in advance for your help!
-Amish
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Unless you need to be able to access the key Set or value Collection for the maps, this is equivalent to a single Map keyed by the composite of the two keys in your example (i.e. the composite of Hashmap1Key and Hashmap2Key, etc). One way to create composite keys isAlternatively, if your keys are Strings you might come up with a unique way to concatenate them, etc.
- Peter
Zakaria Haque
Ranch Hand

Joined: Jan 02, 2002
Posts: 60
It pretty much depends on how much time you can put on this project and what the future needs are.
You can use javabeans to represent a record in your database. It can give you type safety. It will take less memory than using a hashtable for each record, it can be crucial if you are retrieving a lot of data.
Rather than having a hastable represent the results from a table, you can use a broker. The immidiate benefit is, you can use lazy data retrieval, which can be important for large amount of data.
Another good thing about using this type of design is, you are open to use other features in future, like client side caching and bluh bluh bluh. But of course, this is not as important if no one will ever need to enhance this program ever.


tobe bondhu nouka bherao<br />shonabo gaan aj shara raat
 
 
subject: A Design Question