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
addBatch.txt
cofactorAsked:
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.


pstmt.executeBatch();

0
for_yanCommented:
prepareStatement should be outside the loop

pstmt1= conn.prepareStatement(INSERT_INTO_TBL_T_FF_REQUEST);

this should be outside the loop
0

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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

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.setString(6,userVO.getCitizenId());
						pstmt1.setTimestamp(7, CommonUtil.currentTime());
						pstmt1.setString(8, null);
						pstmt1.setString(9, null);
						pstmt1.addBatch();
						i=i+1;
				
				}

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

Open in new window

0
for_yanCommented:

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
0
cofactorAuthor Commented:
excellent
0
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
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.