Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Batch Insertion

 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Am trying to insert data in Batch using int[] updateCounts = stmt.executeBatch();. In case If I have duplicate records it's not inserting original records also simply throwing exception.

Am expecting, In case I have 10 records 2 or duplicate, am expecting remaining 8 to be inserted.

Exception

09/10/12 18:17:32 java.sql.BatchUpdateException: error occurred during batching: ORA-00001: unique constraint (Schema) violated
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
executeBatch will only work if all statements in the batch are successful.
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please suggest me which one will be suitable for my requirement.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could do them one at a time and commit after each rather than using a batch.
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But am doing morethan 2000 insertion in a single shot. If I do one by one then it's a performance issue :-(
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you need to continue after inserts that don't work you cannot batch them. You are going to have to handle them one at a time.
 
Ram Para
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why don't you simply remove duplicates and then insert the records ?
 
Meet Gaurav
Ranch Hand
Posts: 492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At java level I don't have any clue to identify the primary key. Not suitable..
 
Jan Cumps
Bartender
Posts: 2608
14
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Meet Gaurav wrote:At java level I don't have any clue to identify the primary key. Not suitable..
Conclusion: one by one.

Regards, Jan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic