• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

B&S: DuplicateKeyException

 
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Ranchers,
I have a confusion in implemention of method create(String[] data)from the interface DBMain.java!The signature of the method is

My question is under what condition the method should throw DuplicateKeyExcetion?
My understanding: Since the record does not contain any single primary key,it should throw when all the field of data matches with any field in the database file.If I'm wrong please correct me.
[ August 21, 2007: Message edited by: Sanjeev Singh ]
 
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I took very simple approach, which seems to work quite well: not implementing it, because there are few issues which are not clear in assignment about DuplicateKeyException.
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that you need to decide for yourself as a designer since the specification didn't explain it.

some decided that since the specifications didn't explain then just skip it check https://coderanch.com/t/184523/java-developer-SCJD/certification/NX-Notes-design-passed

another alternative would be the one you mentioned..

either way you choose you have to document it well.

regards
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think you should not implement this exception. if you throw this exception when the data match exactly - or defined by your design-decision (matching name/city) - you have to test the update method in the same manner. and there it is only possible to throw a securityexception or a record not found exception. it would be a little bit confusing to throw there a runtime exception.
 
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my URLyBird assignment I took Hotel Name and location as combine primary key. If you notice data provided by SUN also follow the same pattern. Create method will throw duplicate exception if new record has same location and name. But Update method will not throw since it is not allow to change name and location field. Also you have to mention your choice and explain that in future it can change if hotel booking allow same hotels from same location but not in current version. Your assignment is different so look into the data and take decision accordingly.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic