Okay so I am in a Data Structures class and am working on Binary Trees now so I figured I do a little project on the side to experiment.

So I have a frame pop up when the program starts and it has a bunch of information to enter in. When you are done you hit the "SAVE" button and it generates a "Person" and adds the person to a Tree depending on their ID number. So the tree is ordered and easy to search and all that stuff and the tree works great. Only issue is when you close the program all the people disappear from the tree and when you go to search for a "Person" next time you open the program the tree is empty.

How would I go about saving everything so that when I open the program again the tree is still there?

Note: I have a "Storage.java" that contains: add(), remove(), search(), getRoot(); and a private variable called root that is of type TNode (this contains: data, rightTree, and leftTree)

9 Years
Discussion Span
Last Post by JamesCherrill

the easiest / quickest option would be using some file io. for a more flexible / robust option it would be using a database.


A few questions...

1) how would I implement either of those?
2) would I have to download something like MySQL to use a database?
3) If so is Java set up to communicate easily with that type of software?


1) you need to design some kind of structure that will be easy for your program to understand. e.g. how will a tree look like in a text file? this is a very open-ended question, and the same goes for a database. your objective is to represent the person inside this storage, so it can be re-created at next execution.

2) yes, if you want to use a database, you will need the corresponding software, whether that be MySQL or some alternative is up to you.

3) while i don't do a lot of database orientated Java programming, it should be well documented on the Internet and shouldn't be too difficult.


Thanks for the help. I think I will take the easy way out and go with the text document(s). I'll figure something out. i was just unsure If there was something already built in or not. thanks for the help!

[EDIT] do you think a hash table that refers to text files would be more efficient?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.