mkyong / spring-boot

List of Spring Boot Tutorials

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RowCallbackHandler#processRow methoud should not call next() on the ResultSet

Hubbitus opened this issue · comments

https://mkyong.com/spring/spring-jdbctemplate-handle-large-resultset/ provides example code:

import org.springframework.jdbc.core.RowCallbackHandler;

	jdbcTemplate.query("select * from books", new RowCallbackHandler() {
		public void processRow(ResultSet resultSet) throws SQLException {
			while (resultSet.next()) {
				String name = resultSet.getString("Name");
				// process it
			}
		}
	});

and calls resultSet.next() in while loop. But documentation about RowCallbackHandler#processRow clearly stated what it should not be done. Citing:

Implementations must implement this method to process each row of data in the ResultSet. This method should not call next() on the ResultSet; it is only supposed to extract values of the current row.