-1

I want to clear the contents of a result set (but nothing should happen to the underlying database) before using it again to execute a new query?

Is there any method which will delete its data (but do nothing to the underlying database, that's important), so that I can use the same resultset again to retrieve data from another query?

A quick search in the API documentation gave me the idea that deleting things through a method like deleteRow() will actually delete data from the database as well. I just want to reset/refresh/clear the resultSet, so that when it is again used to get results of another query, it should contain data from that query only, and not the previous one.

Or does it automatically remove its contents itself once we have retrieved them from it (through methods like ResultSet.getInt(), ResultSet.getString() etc.)

EDIT:- Can we create new result sets for executing each query in the same method?

4

1 回答 1

2

假设您要执行这样的查询:

ResultSet rs = statement.executeQuery("select * from people");

您将使用以下内容迭代结果:

while(result.next()) {
    // ... get column values from this record
}

然后,您只需重用该变量rs来执行另一个查询,例如:

rs = statement2.executeQuery("select * from cars");

是使用 ResultSet 的教程

于 2014-04-26T21:17:24.930 回答