File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 60050
    
  65

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?
 
Similar Threads
JSTL declarations don't work on WAS6
refreshing the same page with old data
Which is faster - Outer join or Subquery
Advantages and disadvantages of multiple DB calls
which approach is best suited for this scenario?