I have this issue: first, I execute a SQL query using Java and then the result is stored into a resultSet() called rs. The query is as follows:

```
"select ad_id, publisher_id, date, impressions, clicks from table"

```

Then I read all the data using:

```
while(rs.next()){
    (...)
}

```

The problem is that the code we are running needs to re-use all information from rs several times (running stochastic gradient so there are several iterations) but when the it starts a new iteration (going from iteration 1 to 2) rs now is null and we have to execute the SQL query once again which takes quite a long time...

Is there some "direct" way of saving the result from this query into a variable? We considered creating two ArrayLists to save the Integers numbers (ad\_id, publisher\_id...) and one for the date field and then iterate over those lists, but we thought maybe there´s a better and easier way of doing so

In python all we had to do is something like:

```
data = cursor.fetchall()

```

and the variable "data" could be used several times, maybe there´s something similar in Java (I´m still learning Java so I´m not sure)

Thanks for any help