Last time i was facing a problem to connect or link to database for my java program. Actually i have to implement a reservation system, but then after i have sucessfully connect to database, i found out that i can do everything in database, then the class which i create become useless . The class could only used to do input and output + some user interface. And i go to ask the tutor, and he told me not to use database for the assignment........so anyone have any idea beside database? Just use array ? Beside that? Suggestion please ~

Recommended Answers

All 3 Replies

It depends on how you want to access the data. Do you intend to read it all in at the beginning, or do you need to read things in dynamically, as queries?
Similarly, when/how do you update the stored data - transaction by transaction or all in one go?

i think i prefer read it as queries

Without using a database that's not easy. Either you can create your own keyed file format and all the read/write methods it needs, or fudge things a bit by saving each record as a separate file in a directory somewhere, which gives you an easy way to access individual "records" directly if you chose the filenames well.
The easiest way to write & read complex records is usually to create a class (or classes) to hold the data and use ObjectOutputStream and ObjectInputStream to write/read the whole object in one go.
Anyway you do it, it's pretty tacky. That's why databases were invented.
If possible, I would try to get away with writing all the data at the end of a run, and reading it all back in at the start of the next run, and work in memory. You can create an ArrayList of all the data objects which (a) makes it easy to add/remove/retrieve etc and (b) means you can read/write all your data in a single statement by writing/reading that ArrayList object to an Object stream.
Maybe someone else has some better ideas? Come on guys!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.