aspose file tools*
The moose likes JDBC and the fly likes which is better? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "which is better?" Watch "which is better?" New topic
Author

which is better?

pippiri venu
Greenhorn

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


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
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

Moved to the JDBC forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
pippiri venu
Greenhorn

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: http://aspose.com/file-tools
 
subject: which is better?