org.springframework.jdbc.core

Interface RowMapper<T>

  • Type Parameters:
    T - the result type
    All Known Implementing Classes:
    BeanPropertyRowMapper, ColumnMapRowMapper, MappingSqlQueryWithParameters.RowMapperImpl, SingleColumnRowMapper, UpdatableSqlQuery.RowMapperImpl
    Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.


    @FunctionalInterface
    public interface RowMapper<T>
    An interface used by JdbcTemplate for mapping rows of a ResultSet on a per-row basis. Implementations of this interface perform the actual work of mapping each row to a result object, but don't need to worry about exception handling. SQLExceptions will be caught and handled by the calling JdbcTemplate.

    Typically used either for JdbcTemplate's query methods or for out parameters of stored procedures. RowMapper objects are typically stateless and thus reusable; they are an ideal choice for implementing row-mapping logic in a single place.

    Alternatively, consider subclassing MappingSqlQuery from the jdbc.object package: Instead of working with separate JdbcTemplate and RowMapper objects, you can build executable query objects (containing row-mapping logic) in that style.

    Author:
    Thomas Risberg, Juergen Hoeller
    See Also:
    JdbcTemplate, RowCallbackHandler, ResultSetExtractor, MappingSqlQuery
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method and Description
      T mapRow(java.sql.ResultSet rs, int rowNum)
      Implementations must implement this method to map each row of data in the ResultSet.
    • Method Detail

      • mapRow

        @Nullable
        T mapRow(java.sql.ResultSet rs,
                           int rowNum)
                    throws java.sql.SQLException
        Implementations must implement this method to map each row of data in the ResultSet. This method should not call next() on the ResultSet; it is only supposed to map values of the current row.
        Parameters:
        rs - the ResultSet to map (pre-initialized for the current row)
        rowNum - the number of the current row
        Returns:
        the result object for the current row (may be null)
        Throws:
        java.sql.SQLException - if a SQLException is encountered getting column values (that is, there's no need to catch SQLException)