Saving entered information

What should I look into to be able to save entered information.

for example: I write a address book and of course you would like to save the information you enter, how would I go about saving the information. Do I need to connect to a DB or can is be saved without another application, like its own file that can be reopened when the program is started.

Thanks

[379 byte] By [Djanvka] at [2007-11-27 7:46:29]
# 1

You can use classes in java.io to write things to a file. You can then create your own protocol for how to interpret the data from the file. You can also use a properties file in conjunction with the Properties class, which makes the protocol for you.

For instance, if you're using an address book, here's a simple way to store addresses to later be loaded, where the \n's represent new lines, and separate each item from each other:

Firstname1 Lastname1 Streetnumber Streetname St./Rd./etc. City State Zip_Code

\n

Firstname2 Lastname2 ...

\n

Note that if you have to search for a certain address, given a certain name, it will be an O(n) operation... in these cases alternative databases, such as SQL databases, are preferred.

Anyways, you should google "java file io" and read some tutorials on it.

ktm5124a at 2007-7-12 19:27:23 > top of Java-index,Java Essentials,New To Java...
# 2
THanks for the information, I will google that and check it out.
Djanvka at 2007-7-12 19:27:23 > top of Java-index,Java Essentials,New To Java...
# 3
So is there a way I can save the information to a file so when I want the information of a certain person, just that person's information will show up?
Djanvka at 2007-7-12 19:27:23 > top of Java-index,Java Essentials,New To Java...
# 4
If you use a database then all you need is the correct sql statement.If you use a plain text file, then you could read the entire file into memory on startup and perform a search.
floundera at 2007-7-12 19:27:23 > top of Java-index,Java Essentials,New To Java...
# 5

It may be a bit overwhelming, but you can use an "embedded" database, which is basically similar to a M$ Access file (sorry for the analogy :)). Here's one:

http://www.hsqldb.org/

The advantage is that your code is ready to be used with a server-based database then, it's just a question of the JDBC configuration.

If you want to avoid direct JDBC programming, you might want to check this out, altough it's complex enough on its own:

http://www.hibernate.org/

marcelschoena at 2007-7-12 19:27:23 > top of Java-index,Java Essentials,New To Java...
# 6

Has object serialization been mentioned? It's main attribute is that it's 100 times

easier that using a database, although in the fullness of time, this application

sounds destined to use a database :-)

http://java.sun.com/docs/books/tutorial/essential/io/objectstreams.html

Hippolytea at 2007-7-12 19:27:23 > top of Java-index,Java Essentials,New To Java...
# 7
You may use the Database or write to a file format u wish.However DB is a preferred way
Kalyanaa at 2007-7-12 19:27:23 > top of Java-index,Java Essentials,New To Java...