jQuery in Action, 2nd edition*
The moose likes JDBC and the fly likes Problem in using batchs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Problem in using batchs" Watch "Problem in using batchs" New topic
Author

Problem in using batchs

Nagendra Batchu
Ranch Hand

Joined: Jan 23, 2008
Posts: 32
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

Joined: Feb 23, 2009
Posts: 1183
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.


JDBCSupport - An easy to use, light-weight JDBC framework -
Nagendra Batchu
Ranch Hand

Joined: Jan 23, 2008
Posts: 32



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

Joined: Feb 23, 2009
Posts: 1183


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

Joined: Jan 23, 2008
Posts: 32
Thanks for your fast reply ..i will make the necessary changes and try again.

Thanks a lot for your reply.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in using batchs
 
Similar Threads
Servlet hang when performing to much insert function
Problem in Using Update Query in PreparedStatment
ora-0100 maximum number of cursors exceeds
problem in using addBatch
NullPointerException