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

后端 未结 4 1115
花落未央
花落未央 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 04:07

    This is from the Java docs of interface Statement:

    By default, only one ResultSet object per Statement object can be open at the same time.

    So you better use a second Statement or even better a PreparedStatement.

    And to execute an INSERT SQL statement you should use executeUpdate() instead of executeQuery().

提交回复
热议问题