• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

which is better?

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved to the JDBC forum.
 
pippiri venu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am using mysql database.
so unique index is possible in mysql?
can u give some example.
 
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic