• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

How Spring JdbcTemplate handles mutliple rows/ objects being returned?  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Rancher
Posts: 3931
45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The query method does the iterating over the ResultSet, calling your mapper for each row.
 
Pupa Chaudhuri
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dave.
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?
 
Dave Tolls
Rancher
Posts: 3931
45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
There's something like:

in the query method.
 
Pupa Chaudhuri
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Dave.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!