Meaningless Drivel is fun!
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes database unique fields Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "database unique fields" Watch "database unique fields" New topic

database unique fields

friso dejonge
Ranch Hand

Joined: Jul 11, 2002
Posts: 162
Hi all,
First of all, i've read loads of comments on the javaranch, and i have to say it is a very good and helpfull resource.
After reading some questions on database, am I right to assume that on this occasion the flightnumber is the unique key in the database for each record. I do know, that in real life this is not the case, but the find function in Data class, uses the first arrayfield (values[0].equals(toMatch) as a right match. Also the add method checks on this key to verify if there are duplicate keys. So can anyone confirm the flightnumber is the unique key. ?

swimming certificate (A & B), shoelaces diploma, and some useless java ones.
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Well, yes and no. Good Answer Mark.

Yes you use the find methods by passing the flight number, and we hope that it is unique. And in the case of the records currently in db.db file it is unique. And the assignment does not have us add any more flights, so therefore it is unique. But let's say down the road they want that to change, so then it won't be the primary key.
I think they added it that way because it makes the assignment easier for us to just get the first field and pass it to find and it finds the record for us.
To me record number is the only guaranteed unique number for the db file.

Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
friso dejonge
Ranch Hand

Joined: Jul 11, 2002
Posts: 162
true, but even when adding records, it is enforced that the flightnumber is unique. So if at a later stage they change the uniqueness, then code for adding, and finding has to be changed as well.
If I add this in my assumptions/considerations...
I agree. Here's the link:
subject: database unique fields
It's not a secret anymore!