Meaningless Drivel is fun!*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes createRecord question! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "createRecord question!" Watch "createRecord question!" New topic
Author

createRecord question!

xi brian
Ranch Hand

Joined: Mar 06, 2008
Posts: 30
/** Creates a new record in the database (possibly reusing a
* deleted entry). Inserts the given data, and returns the record
* number of the new record.
* @param data the new record to insert into the database
* @return the index of the new record in the database
* @throws DuplicateKeyException indicates the record already exists.
*/
public long createRecord(String [] data)throws DuplicateKeyException{
return 1L ;
}

when should i consider a input record to be Duplicate?

thank you in advance
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2258
    
    3

Howdy, my buddy.

Well, you'll have to find a primary key in the structure of your record. It has to be something that does not repeat, you know... for example, if you have room number in your record, this could be your primary key. So, if you receive a record where the room number is a number that is already in use, then you could throw a DuplicateKeyException. But, in my case, I have the URLyBird 1.3.1, and the structure they gave me doesn't have a field that could be primary key, so to read records, update, or delete, I use the record number (which is the physical position of the record in the database), and since 2 records cannot be in the same entry in the database file, I never throw a DuplicateKeyException.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
xi brian
Ranch Hand

Joined: Mar 06, 2008
Posts: 30
"the record number (which is the physical position of the record in the database), and since 2 records cannot be in the same entry in the database file, I never throw a DuplicateKeyException."

record number must be different in the data base, but the field in each record could be exactly the same , in this case, i guess it is not correct to use recored number as key

am i right?
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2258
    
    3

Well, the record number is not exactly a field of a record, it is just the position the records appear in the database. So, it'll never repeat. But your thought was correct, a field that repeats cannot be primary key.
xi brian
Ranch Hand

Joined: Mar 06, 2008
Posts: 30
"Well, the record number is not exactly a field of a record, it is just the position the records appear in the database. So, it'll never repeat. But your thought was correct, a field that repeats cannot be primary key."

so how can i decide which combination of my field is the key?
since all fields could be repeated except owner.
but ont he description, it says we do not interact with the owner id.
so we can not make it as primary key.
Mike Bailey
Greenhorn

Joined: Mar 10, 2008
Posts: 9
It really depends on the db schema given in your instructions. The instructions I have (URLyBird) don't have a primary key in the schema. For example there can be multiple records with the following values:
[*]Hotel Foo
[*]Atlanta
[*]4
[*]no
[*]$200
[*]2008/03/25
[*]Owner
So the DuplicateKeyException would never be thrown since there is no possible way to have a duplicate.
xi brian
Ranch Hand

Joined: Mar 06, 2008
Posts: 30
i have exactly the same fields as yours, so i guess i do not need to worry about exception.

thank you for you help
Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
Originally posted by xi brian:
i have exactly the same fields as yours, so i guess i do not need to worry about exception.

thank you for you help


You choose not to use any primary key (or perhaps your primary key is the recNo) and not to throw any exception. These are design choices you might want to document.

You still need to "worry" just a little about it

Alex
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: createRecord question!
 
Similar Threads
DuplicateKeyException - B&S
NX: questions about javadoc, HELP!
Add New Record - Problem with GUI and JPanels
URLyBird Primary Key
NX: DuplicateKeyException