• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

explanation on RowMapper's mapRow method

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm unable to comprehend the method mapRow(ResultSet rs, int rownum) in the RowMapper interface. I tried to go through the API but i'm still not clear on this.

Can anyone please explain what this method does and what's it used for.

Thanks
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to post this yesterday


So JDBC queries return ResultSet objects. But your application has Domain objects like Order or Item. You need to convert the ResultSet into a Domain object. This normally tedious pain in the arse work, that is error proned, and in different queries might have duplicate code.

By using a RowMapper you can centralize that code in one class.

So when you run a Query that returns rows into a ResultSet and you pass in a RowMapper to the JdbcTemplate, then the template will do the work of looping through the resultset and passing it row by row to the mapRow method. The return of the mapRow will be an Object of the type that you convert the row to. In the mapRow method you write the code like

Order order = new Order();
order.setOrderDate(rs.getDate(0));
etc.

I forget the exact api method call on result set to get the field value of a date, but that is the general idea.

Mark
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic