Why is While (rs.next()) statement ending after 1st iteration?

后端 未结 4 1130
花落未央
花落未央 2021-01-20 03:20

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

4条回答
  •  忘掉有多难
    2021-01-20 03:58

    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 ResultSet object is automatically closed when the Statement object 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.

提交回复
热议问题