What is RowMapper, ResultSetExtractor, bind variables and query types?

I know how to use the JDBC and DAO pattern, but I still have questions about this:

  • What are the uses of RowMapper and ResultSetExtractor ?
  • What is a binding variable?
  • Are queries types of List?
+4
source share
1 answer

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 .

+14
source

Source: https://habr.com/ru/post/1385045/


All Articles