Three things you could try, sorted by estimated gain/change:
- Switch off AutoCommit and do a manual commit() every few lines or even only
once after the loop. This should give you the biggest gain/change.
- It is not necessary to prepare(...) the statement handle within each iteration.
But I guess this will not have a big impact.
- If program execution is still too slow, try to use the batch import tool of your DB.
Create an import file first, then use the batch loader.
HTH