Am I correct in thinking that for a database with n USERS, the following code results in at least n interations with the database?
Statement stmt = con.createStatement();
ResultSet srs = stmt.executeQuery(
"SELECT FAVOURITE_COLOR FROM USERS");
while (srs.next()) {
//performSomeAction on srs.getString("FAVOURITE_COLOR");
}
Would it then also be possible to extract the FAVOURITE_COLOR from all users in 1 I/O interaction with the database?
And if so would that posssibly cause an memory overflow in the program if there are too many users?
Your sample code does a single roundtrip to the database.
In a simple implementation,
executeQuerywill wait for the entire dataset to be retrieved from the database. Then each call tonextwill move immediately to the next row.