Difference between RowCallbackHandler and RowMapper
Joined: May 27, 2009
What is difference between RowCallbackHandler and RowMapper?
Joined: Aug 31, 2008
Both RowCallBackHandler and RowMapper are both for retrieving the results from a ResultSet which takes the responsibility to process each row of data in the ResultSet. Both interface methods should not call next() on the ResultSet. It requires to extract values of the current row and process the data on per-row basis.
RowCallBackHandler's processRow(ResultSet rs) does not return object which is having the result.If require it can store the result in its instance variable and then make it available it to DAO but for this it requires to be designed as stateful.
So this type of method(processRow()) is generally implemented to process the result like preparing XML document with the result data.
But RowMapper's mapRow(ResultSet rs, int rowNum) can return an Object representing the result object for the current row.
In general this interface is designed as stateless to make it reusable and reduce the memory requirements.