I have a requirement to do hundreds of inserts in a certain part of a web app. It currently works by looping over a prepared statement and committing each one individually. This process is very prone to a Transaction timeout (Extending the timeout time is not viable). It needs to be completely rewritten to be more efficient. I have been able to come up with two ideas:
Instead of using a prepared statement use a normal statement and simple loop over each additional item I want to insert and append it to the query. I am not very concerned with sql injection because this all stems off of one single id that is verified earlier in the process. Please feel free to tell me if this is naive.
Have a stored procedure in the database that does all of the inserts. I would call it by using a callable statement.
If there is another (better) way not mentioned here, please let me know.