Link to home
Start Free TrialLog in
Avatar of srikotesh
srikotesh

asked on

java.lang.ArrayIndexOutOfBoundsException is coming after jdbc batch executed

Hi Experts,

java.lang.ArrayIndexOutOfBoundsException is coming after jdbc batch executed

batch size 5000
i have total -5500
batch executed 5000 inserte data successfully
rest of the records failed to execute

if i give batch size 5500
all the date is inserted successfully

refer code here
https://www.experts-exchange.com/questions/29110374/JDBC-Batch-insert-causes-ORA-01000-maximum-open-cursors-exceeded.html
Avatar of Alex [***Alex140181***]
Alex [***Alex140181***]
Flag of Germany image

That's because you're doing a "conditional" insert via "executeBatch":
this
if (++insertCount % batchSize == 0) {
								logger.debug("inside execute batch insert "
										+ insertCount);
								preStmt.executeBatch();
							}

Open in new window

and this
if (insertCount % batchSize != 0) {				
				preStmt.executeBatch();
			}

Open in new window

If you'd set batchSize to 10, then every 10 rows a  (batch) insert would occur. But if you have a total > 10 rows, the rest wouldn't be touched because your code just doesn't bother ;-)
You'll need to "think" of those, too...
Avatar of srikotesh
srikotesh

ASKER

Hi Experts,

total records 5527
now i gave batch size as 2000
it is executing perfectly for both conditions.

I didn't understand why it is not working if the batch size as 5000.
Is there any restriction for batchsize?


preStmt.setInt(1, tdmDocumentHdr.getCustId());
preStmt.setString(2,
		tdmDocumentHdr.getCountryCode());
preStmt.setDate(3, tdmDocumentHdr.getCreatedDate());
preStmt.setDate(4, tdmDocumentHdr.getModifiedDate());
preStmt.setDate(5, tdmDocumentHdr.getDocDate());
preStmt.addBatch();
if (++insertCount % batchSize == 0) {
	logger.debug("inside execute batch insert "
			+ insertCount);
	preStmt.executeBatch();//executed 2k,4k
}
						
if (insertCount % batchSize != 0) {				
	preStmt.executeBatch();//executed rest of the records here successfully
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Alex [***Alex140181***]
Alex [***Alex140181***]
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
How's the status here?
Thanks a lot, I hope, the information will help you ;-)