0

when I get a ResultSet output, it is always "plugged" to db, so every time I use "resultset.next()" it actually do requests to db. I always thought that when I perform something like this:

public static ResultSet getInfoFromDB(){
        ResultSet resultSet;
        try{
            Connection connection = connectDB();
            Statement statement = connection.createStatement();
            resultSet = statement.executeQuery("SELECT * from tablex");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return resultSet;
    }

I thought that since I am selecting * from table, that it was return ALL the table into the variable resultSet.... but it acutally isn't.

How to retrieve all the table and save into a "local" (non "plugged" to db) variable that I can return and manipulate it in local?

Allexj
  • 1,375
  • 6
  • 14
  • 29

1 Answers1

0

The MySQL Connector/J fetches rows in batches, according to the "fetchSize". You can set this as a property of the statement.

Read the documentation about ResultSet here: https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-implementation-notes.html

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828