aspose file tools*
The moose likes Beginning Java and the fly likes data structures and databases Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "data structures and databases" Watch "data structures and databases" New topic
Author

data structures and databases

vicky kieu
Greenhorn

Joined: Jul 09, 2005
Posts: 1
i have a database and i need to store all the data into a data structure. but which one? my database contains authors, coauthors, and book titles. my data structure should make it possible for me retrieve all authors and coauthors who have worked on the same books together.

can anyone help me out? recommend a data structure for me to use?

thanks!
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9047
    
  10
How about a HashMap?


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
I don't think a single data structure will fit your needs here. I agree with Marilyn that a Map will be helpful. You will probably also need to use a List to keep track of all the authors for a particular book. I would create two classes: Author and Book. Then you can use a Map with a Book object as the key and a List of Author objects as the value.

If you are unfamiliar with the data structures that are provided by the Collections API, I suggest you check out this tutorial. It will help you get started using them. You will also want to use the Java API docs for the version of Java you are using. These are a great reference when you need to look up a specific class or method.

HTH

Layne


Java API Documentation
The Java Tutorial
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
You can make object models that mimic your database model. One bit that goes backwards is one-to-many. In the database the many all have pkey pointers to the one. In the object model the one probably has a collection of references to the many.

Your database might have a many-to-many with a joining relationship table in between. Your object model can duplicate that if you need to put some attributes on the relationship, or just give each side a collection of references to the other.

Google for "object relational mapping" for much more. HERE is an article by Scott Ambler. He's written tons on the subject.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: data structures and databases