Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

(B&S)DuplicateKeyException

 
Christopher Bareja
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, everybody,

I'm working on assigment, but this is an early phase - just trying to make some most important choices and make sure i've undersdood instructions.

My problem is: For defined inteface for DB insert method has "throws DuplicateKeyException". What is assumed to be a key in this base? There is not even half a word about this exception in the rest of the text.
 
Martin de Boer
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Christopher Bareja:
Hi, everybody,

I'm working on assigment, but this is an early phase - just trying to make some most important choices and make sure i've undersdood instructions.

My problem is: For defined inteface for DB insert method has "throws DuplicateKeyException". What is assumed to be a key in this base? There is not even half a word about this exception in the rest of the text.


Hello Christopher,

I've wondered about that also. I implemented the method without throwing that exception. If in the interface the method is defined throwing a DuplicateKeyExcpetion, this doens't mean your implementation throws that exception. About that key ... in my assignment (URLyBird) there is no real key. There's only the record number to identify a record. This way it's not possible to get a DuplicateKeyException.
 
Christopher Bareja
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's exactly my feeling. I don't find anythng could work as a key. Maybye not throwing an exception is an idea. But sti;ll need handle this exception. So my gui must be prepared for signaling an error situation that woulg never happen ... That's not not nice... :/

Anyway, thx a lot, Martin. Any other opinions?
/Chris
 
Marcio Aun Migueis
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christopher,

I had this kind of doubt also, and Andrew ( from the book ) told me that we don't have to throw this exception. About the key, it does't exits now, but it could exist in a "future implementation". Don't worry too much about these things.

M�rcio
 
Christopher Bareja
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Don't worry too much" is easy to say
Well, It will be easier in the middle of project, when I'll have just a straight way to the end. Now there are many decisions to make. Problem is, there is no opimal way to do this project

I've staterd to implement database access first. I feel best at swing, to I'll leave this to the very end I guess. So, quite a long way before me
 
Gary Hellman
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought that the "key" would be - just whatever you would normally use to distinguish one record from another.

In the sample data file that was included with my project, it was possible to see and use a combination of the "fields" (they also mentioned this combination of fields for the search ) to make a "unique enough" key - your project may be different.

And then, when you do a "Create" with the same data in those key fields, there should be a duplicate key exception.
 
Simon Twigg
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have just passed the SCJD.

I defined a key to be the phyical location of a record in the db file.

A DuplicateKeyException was declared in the signature of the db insert method but I did NOT throw a DuplicateKeyException in the body of the method. Did not lose any marks on this. Got full marks for the Data class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic