I am using jsp - servlet - jsp architecture for my application.
I have used employeeId as primary key in my employees table in mysql database. Now if a duplicate key is entered in the form, the database is throwing error stating duplicate primary key. Is there any way to handle that error and send an error.jsp instead?
That said, IMO it's a Very Bad Idea to allow someone to set the primary key on the form: the primary key should be "invisible", for all intents and purposes, to application users.
Vishwanath Krishnamurthi
Ranch Hand
Joined: Jun 04, 2007
Posts: 331
posted
0
the primary key should be "invisible", for all intents and purposes, to application users.
Primary keys should not be made out of business data. Rather, they should just be id numbers that have no meaning and are only used for identification and relations.
Try creating an ID generator. System.currentTimeMillis() is useful or just seacrh google.
About error handling, follow David's advice.
Vishwanath Krishnamurthi
Ranch Hand
Joined: Jun 04, 2007
Posts: 331
posted
0
Primary keys should not be made out of business data. Rather, they should just be id numbers that have no meaning and are only used for identification and relations
Guess this is to do with what I came across as 'surrogate keys'... thanks.. will read about them.
System.currentTimeMillis() is useful
can't use this I guess, if its a web-app that is distributed...