How PreparedStatement.executeQuery works? Does it fetch results from database and I loop through them? Or it fetches the first result, and on record.next continues with sql query to the next row?
ResultSet record = statement.executeQuery("select * from users");
while (record.next()) {
//do something
}
thank you
From the documentation:
Statement
ResultSet
As a representation this means the statement is executed once and when iterated is iterated over the result of that execution.
But how the result from database is handled depends really on the implementation. To make a contrast I will refer two databases MSSQL, MYSQL.
MSSQL
The documentation of MSSQL driver that comments exactly how the results are handled you can find here:
MySQL
MySql implementation of JDBC interface that you can read here: