Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding duplicate insert problem

 
vijay jamadade
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

I am inserting the csv data through java in oracle.I want to check the whether the data I am inserting already exists in
table or not in insert query itself. Can I do that.

Because checking through select query before inserting the data is making the application heavy.

thanks in advance.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34401
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vijay,
There are two approaches:
1) Do a select first
2) Insert it anyway and fail on duplicate constraint

Which one you choose depends on the likelyhood of a duplicate occurring.
 
vijay jamadade
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Insert any way does not work here because when exception occurs while inserting records one by one the code goes out of loop afterwards in java. And select first I think making the application heavy as for every insert it needs to be fire a query. How to handle that.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic