I am using a SELECT statement to get data from a table and then insert it into another table. However the line \"stmt.executeQuery(query);\" is inserting the first line fro
You are re-using the Statement that was used to produce rs on the last line of your loop.
This will close the ResultSet rs. As stated in the documentation:
A
ResultSetobject is automatically closed when theStatementobject that generated it is closed, re-executed, or used to retrieve the next result from a sequence of multiple results.
You need to use a second Statement object to execute the INSERT statements.