The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

phillips1021 (66) [Avatar] Offline
#1
emilio_77 (2) [Avatar] Offline
#2
Re: Spring JDBC queryForObject
Hello,

I've noticed the same.

I've found: "as of Spring 3.0: Use the method using the newly genericized RowMapper interface instead since the RowMapper and ParameterizedRowMapper interfaces are equivalent now."

If you use RowMapper instead of ParametrizedRowMapper, you should solve.

public Spitter getSpitterById(long id) {
return jdbcTemplate.queryForObject(
SQL_SELECT_SPITTER_BY_ID,
new RowMapper<Spitter>() { // here I use RowMapper instead of ParametrizedRowMapper
public Spitter mapRow(ResultSet rs, int rowNum)
throws SQLException {
Spitter spitter = new Spitter();
spitter.setId(rs.getLong(1));
spitter.setUsername(rs.getString(2));
spitter.setPassword(rs.getString(3));
spitter.setFullName(rs.getString(4));
return spitter;
}
},
id
);
}

Bye.

Emilio