I am new to Spring and learning its JDBC Framework.
I came across a piece of code -
Below is snippet to retreive a list of Student object. This means the SQL query returns more than 1 row in the ResultSet rs.
I was going through the RowMapper<T> spring documentation java.lang.https , and found that mapRow() is not supposed to
call next() on the ResultSet rs as it is supposed to map only the the current row with the Java domain object.
My question is if the ResultSet rs has multiple rows of data, who or what causes the cursor to move to the next row and perform mapping using mapRow()?
Is it the queryForObject() method of JdbcTemplate doing something implicitly or something else?
I am looking for an explanation how this work gets done.
The query method does the iterating over the ResultSet, calling your mapper for each row.
posted 1 month ago
In the query() method only 1 instance of RowMapper implementation(StudentMapper) is provided here.
When the query() method iterates over the result set in backend, it makes use of that one instance of the mapper and calls the mapRow() method as many number of times as there are rows in the ResultSet rs?