This can be done by using the query method of JdbcTemplate. There are two interfaces that helps to do this:
ResultSetExtractor:
It defines only one method extractData that accepts ResultSet instance as a parameter and returns the list.
Syntax: public T extractData(ResultSet rs) throws SQLException,DataAccessException;
RowMapper:
This is a enhanced version of ResultSetExtractor that saves a lot of code.
It allows to map a row of the relations with the instance of user-defined class.
It iterates the ResultSet internally and adds it into the result collection thereby saving lot of code to fetch records.