Q1: These theses along with the RowCallbackHandler
are often used by JdbcTemplate
when starting the database. Which interface you implement, how you implement it, and which method you use in JdbcTemplate
depends on your database and what query you want to execute. From the Spring API document and some additional comments:
RowMapper :
The interface used by JdbcTemplate to match ResultSet strings for each row. Implementations of this interface do the actual work of mapping each row to a result object
i.e. RowMapper
typically used to map objects when there is a one-to-one relationship between a row in the database and the resulting object.
ResultSetExtractor :
A ResultSetExtractor is usually stateless and therefore reusable
ResultSetExtractor
implementations typically create a single object from multiple rows, which is subsequently returned. It has no status because the implementation class does not maintain state between method calls.
RowCallbackHandler :
Implementations of this interface do the actual work of processing each row [...] Unlike ResultSetExtractor, the RowCallbackHandler object usually has a state: it stores the state of the result inside the object in order to be available for further control.
RowCallbackHandler
used for queries such as updating or deleting rows. It is also used when you need to track status through a ResultSet
, such as the number of rows in a RowCountCallbackHandler .
source share