Consider a case that if I want to insert 60 records of student, for their attendance. I just need to do bulk insert of all 60records at a second.Can any one get a sample query.Even if there is chance for batch update how to do it,can any one get me a sample querry.
Use PreparedStatement with '?' placeholders on how many columns you have. And setautocommit as true
Have each student record available as JavaBean and add it a collection (preferably ArrayList)
In a While or for loop (iterate ArrayList) , fetch each record and execute preparedstatement created code.
This way , even if it fails at 40 th record , you would have 39 records committed successfuly.
Use Batch update only when (in your case) you think all the individual inserts/updates combines to make a single transaction.
This is the particular statement which make my sample code to be reasoned.
That being said, the best approach is often to show enough code to point the questioner in the right direction.
Next thing, when I see the OP is looks like a little confused about whether to use Batch statement or simple for loop for inserting the records, I thought this time just let her know how the simple code looks like for the same.
And what you explained in your first reply is same as the few lines of code of mine.(Yes asked the OP to use transactions and explain the difference between the batch and loop )