Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in using batchs

 
Nagendra Batchu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

I have a two number say FROMNUMBER and TONUMBER in a formBean , Like this i have ArrayList of FormBeans , Now my requirement is to insert each individual number into one table.So i am using Batchs to add all the number.

The code is a follows----------

for(int i=0;i<primarySuccess.size();i++){
PrimaryUploadForm primaryForm=new PrimaryUploadForm();
primaryForm=(PrimaryUploadForm)primarySuccess.get(i);
for(long u=primaryForm.getSeriesFrom();u<=primaryForm.getSeriesTo();u++){
statement5.setInt(1,maxTrans);
statement5.setString(2,primaryForm.getItemCode());
statement5.setString(3,u+"");
statement5.setString(4,"");
statement5.setString(5,primaryForm.getInvoiceNumber());
// statement5.executeUpdate();
statement5.addBatch();
statement5.clearParameters();
}}
statement5.executeBatch();

if there are totally 1,25,000 numbers , if i use batchs only some number are getting inserted(some 12,000) numbers
but if i comment the addBatch and use executeUpdate() then each individual record getting inserted but its taking more time to insert the records,

Please suggest some solution for this problem.
>
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

please put your code between the code-tags so it's easier to read.

I'm having problems understanding your code. For instance why do you create a new instance of PrimaryUploadForm when you then in the next line reassign the same variable with an object from the list.

Also, I dont know where 'statement5' comes from, so I don't get the context.
 
Nagendra Batchu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



i had create a new instance so that it will be essay to fetch the SeriesFrom and SeriesTo
is that the cause of the problem ?

Please suggest the changes in the code

>
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is non-sense. You instantiate a new PrimaryUploadForm() and assign it to primaryForm.
After that you reassign primaryForm, hence the previously created PrimaryUploadForm goes into the Nirvana.

As for the batches, maybe there is an internal buffer or limit. And since you batch together 125,000 queries, it strips some out.
Try batching together 1000 queries and then flush.

You could achieve this by adding the following code:

 
Nagendra Batchu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your fast reply ..i will make the necessary changes and try again.

Thanks a lot for your reply.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic