permaculture playing cards
The moose likes JDBC and Relational Databases and the fly likes which is better? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "which is better?" Watch "which is better?" New topic

which is better?

pippiri venu

Joined: Apr 19, 2005
Posts: 8
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:

venu gopal p
Choon-Chern Lim
Ranch Hand

Joined: Aug 29, 2005
Posts: 74
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

Joined: Jan 10, 2002
Posts: 63865

Moved to the JDBC forum.

[Asking smart questions] [About Bear] [Books by Bear]
pippiri venu

Joined: Apr 19, 2005
Posts: 8
i am using mysql database.
so unique index is possible in mysql?
can u give some example.
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
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);

SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
I agree. Here's the link:
subject: which is better?
jQuery in Action, 3rd edition