addBatch problem in PreparedStatement

Here is a small code attached .

This code  loops 3 times.

 In eclipse debugger , when I  inspect  the pstmt1  I see only  the last loop  values.

Whats wrong with this code ?   why all the queries are not added into batch ?  

System: mysql5   and mysql-connector-java-5.1.14-bin.jar , jboss 5.0
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chaitu chaituCommented:
I Didn't see pstmt.executeBatch() after for loop in your code.


prepareStatement should be outside the loop

pstmt1= conn.prepareStatement(INSERT_INTO_TBL_T_FF_REQUEST);

this should be outside the loop

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

chaitu chaituCommented:
						pstmt1= conn.prepareStatement(INSERT_INTO_TBL_T_FF_REQUEST);

for (String breed : ffgroupVO.getBreedTypeId()) {
						pstmt1.setString(1, group_application_Number);
						pstmt1.setInt(2, Integer.parseInt(breed));
						String quantity=ffgroupVO.getRequiredQuantity().get(i);
						pstmt1.setInt(3, Integer.parseInt(quantity));
						pstmt1.setString(4, null);
						pstmt1.setString(5, null);
						pstmt1.setTimestamp(7, CommonUtil.currentTime());
						pstmt1.setString(8, null);
						pstmt1.setString(9, null);

// Execute the batch
    int [] updateCounts = pstmt.executeBatch();

Open in new window


pstmt1= conn.prepareStatement(INSERT_INTO_TBL_T_FF_REQUEST);

it should be before the lopp - you carete every time new and
so it has only one set added
cofactorAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.