• 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
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

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

 
Greenhorn
Posts: 5
  • 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.

 
Master Rancher
Posts: 4042
47
  • 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: 5
  • 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
Master Rancher
Posts: 4042
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
There's something like:

in the query method.
 
Pupa Chaudhuri
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Dave.
 
His brain is the size of a cherry pit! About the size of this ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!