File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

database error handling

 
Ashish Nandan
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 331
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64205
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Hector Tenedero
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try creating an ID generator. System.currentTimeMillis() is useful or just seacrh google.
About error handling, follow David's advice.
 
Vishwanath Krishnamurthi
Ranch Hand
Posts: 331
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic