Just a tip, if your code goes that way, you may try using the addBatch method of the prepared statement. Your code will have a great impact on your network, since you will send sql statement back and forth from your server everytime your loop is executed.
At the end of your loop, you may issue the execute() statement to execute your sql statements once.