aspose file tools*
The moose likes Servlets and the fly likes database error handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "database error handling" Watch "database error handling" New topic
Author

database error handling

Ashish Nandan
Greenhorn

Joined: Jun 03, 2009
Posts: 22
HI all,

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?


Regards,
Ashish Nandan
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Catch the exception and redirect?

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
the primary key should be "invisible", for all intents and purposes, to application users.


Can you please explain this?

invisible- like to have it generated?

Blog
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61657
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Hector Tenedero
Ranch Hand

Joined: Oct 13, 2008
Posts: 31
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
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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: database error handling