• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

which is better?

 
pippiri venu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i have huge data in 1.jsp . if i submit then the data goes to d/b. if i want to avoid duplication.(if any one refresh or double clilck that 1.jsp file again).

so here r 2 ways two avoide duplications.
1) storing the entire data into a session then comparing before insert.

2) make a query then check duplications.

so which one is the best?

or is there any other ways... :roll:
 
Choon-Chern Lim
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The third way is to create unique index in your database table. Then wrap your sql insert statement with a try catch.

When user tries to refresh the submitted form, it will try to insert the duplicates in your database table, but the unique index ensures your table integrity and therefore throws an exception. You can handle the exception in a graceful way so that user doesn't see the ugly exception.
[ September 02, 2005: Message edited by: Choon-Chern Lim ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65123
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the JDBC forum.
 
pippiri venu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am using mysql database.
so unique index is possible in mysql?
can u give some example.
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Usually unique is forced by keyword UNIQUE, but in mysql it will probably depends on version which you are using.

create table foo(bar int UNIQUE);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic