The error u r facing here is due to issuing commit within the for loop .

In order to overcome this error what u just need to do is issue commit after the end loop; thats it. And the program will work fine. It has been tested at my end.