• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

createRecord question!

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
/** 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
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
xi brian
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have exactly the same fields as yours, so i guess i do not need to worry about exception.

thank you for you help
 
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
reply
    Bookmark Topic Watch Topic
  • New Topic