spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

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

Open Hubbitus opened this issue 5 years ago • 0 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.

Hubbitus avatar Jun 11 '20 17:06 Hubbitus