Moving db.setTransactionSuccessful() to the proper location outside of the loop.