Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

DuplicateKeyException

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public int create(String [] data) throws DuplicateKeyException;is the method declaration in DBMain interface,here I don't see any possiblity for DuplicateKeyException because recno is the unique key and we don't specify recno when we create a record and we either a new record at the end or reuse a deleted record and when it comes repeating the data, a hotel can have multiple rooms with the same description for a customer.
Any ideas are appreciated.
Thanks
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I interpreted this to mean that some of the fields in the database actually constituted a primary key. for my assignment this was Service Provider and Location (contractor assignment). But that's pure guesswork on my part...
ms
 
Ramesh Tiwari
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike,thank you very much for your reply.
Does your assignment's documentation explicitly say what fields constitute primary key because docs for URLyBird 1.3.3 doesn't say anything like that, uniquesness is solely maintanied based on recno which is like a serial#.
The database that URLyBird uses contains 7 fields:
1)name(Hotel name)
2)location (city where this hotel is located)
3)size (maximum room occupancy)
4)smoking (smoking or non-smoking flag)
5)rate (charge per night for the room)
6)date (day for which this room is booked)
7)owner (customer name or ID who will occupy this room)
Nothing can be ever unique in the above fields even as a combination because a hotel can have multiple identical rooms and a customer can book multiple rooms in the same hotel for the same day.
recno is the only possible primary key,but we don't allow the client to choose recno i.e where he wants to store the record in the DB file, we control it from within the application.
Hence I don't see any scope for DuplicateKeyException.
Please let me know if you need more info.
Thanks
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ramesh,
I've got URLyBird 1.2.1 and I cannot define a primary key neither, because as you say, there is no field in our file against which we can test for uniquesness.
So I think that the use of a primary key for a given table is optional (could be used for example in a future customers table to make sure that all customers have a different ID). You could define it as :

and in createRecord() do something like this :

But there is an issue in updateRecord() then :
  • it should do the same test but as it doesn't throw DuplicateFieldException, we cannot
  • or it should ensure that the primary key is never changed (but it would require one more specific exception too).


  • So another approach could be to ignore the primary key issue for the assignment telling in choices.txt why we did so :
  • no need for a primary key in the current URLyBird database
  • DBAccess don't let us implement such a key in a consistent way because of the updateRecord signature


  • Cheers,
    Philippe.
    [ July 24, 2003: Message edited by: Philippe Maquet ]
     
    ranger
    Posts: 17346
    11
    Mac IntelliJ IDE Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I agree, the Hotel reservation system does not have a field combination to make a Primary key. Unless they would specifically say that a Hotel can only have one room of a certain type. But from what I hear that isn't there. So while I think a DuplicateKeyException is needed for a generic Database's create method. For this instance it doesn't appear to be valid.
    However, I also would not remove this from the signature.
    Good Luck. I don't have an real answer for this question which pops up very often with the Hotel Reservation System.
    Hopefully Sun might be able to shed a little light on this discussion. Has anyone sent an e-mail to who2contact?
    Mark
     
    Well don't expect me to do the dishes! This ad has been cleaned for your convenience:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
      Bookmark Topic Watch Topic
    • New Topic