JDBC / Spring - execute sql query to get iterator of results

So far, I have used "SimpleJdbcTemplate" and used the "RowCallbackHadler" to handle the entire query result. For now, I would like to get an object similar to an iterator, which I could query for the next row of the table. Is the following behavior possible in Spring / jdbc (preferably slapping)?

+4
source share
2 answers

You can try using the JdbcTemplate query forRowSet method

public SqlRowSet queryForRowSet(String sql, Object... args) throws DataAccessException 

http://static.springsource.org/spring/docs/current/javadoc-api/org/springframework/jdbc/core/JdbcTemplate.html#queryForRowSet%28java.lang.String,%20java.lang.Object...% 29th

+1
source

You can use ResultSetExtractor instead of RowCallbackHadler . Methods in JdbcTemplate that accept the latter will also accept the former.

+1
source

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


All Articles