This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Spring and the fly likes explanation on RowMapper's mapRow method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "explanation on RowMapper Watch "explanation on RowMapper New topic

explanation on RowMapper's mapRow method

Abdul Rahman
Ranch Hand

Joined: Jul 04, 2008
Posts: 63

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.


SCJP5, SCWCD5, [scwcd wall of fame]
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

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();

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


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: explanation on RowMapper's mapRow method
It's not a secret anymore!