This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Prevent Multiple entries stored in database

 
Rajendra Prakash
Ranch Hand
Posts: 293
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider am using java , struts, hibernate and oracle. How can i prevent duplicate entries stored in
database. One way is to make field as Unique . For example i am entering name "prakash" in jsp page ,
prakash is already available means how can i prevent it.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is wrong with making it unique in the database?
 
Rajendra Prakash
Ranch Hand
Posts: 293
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to prevent duplicate entries programmatically , not in DB.
 
Rob Spoor
Sheriff
Pie
Posts: 20380
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'd need to check before each insert whether or not there is a conflicting entry in the database.
 
Bharath Raja
Ranch Hand
Posts: 111
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rajendra Prakash wrote:How to prevent duplicate entries programmatically , not in DB.


read a field one by one and compare it with our new entry using loops... But wait a minute... this is very vague idea...let us wait for some ones better solution..
 
Rajendra Prakash
Ranch Hand
Posts: 293
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes i want to check before each insert whether or not there is a conflicting entry in the database.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course, that is not going to be a 100% guaranteed mechanism. How do you prevent another process inserting duplicate data after your check but before your insert without pessimistically locking the table? And why use pessimistic locking when databases provide a mechanism already in the form of unique indexes?
 
Rajendra Prakash
Ranch Hand
Posts: 293
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its ok . I also want to know ,how can we do after inserting a record
 
Rob Spoor
Sheriff
Pie
Posts: 20380
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't anymore, because the uniqueness is already violated.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To check is there is a double you need all the information so you have two options:

Hold all the information in memory (then what's the use of the database?)
Contact the database to check if the element already exists.

If you use one of these options you'll need to check for concurrent access and exposure of your datastructure.
The best solution is to set a constraint on the database.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic