Reputation: 2882
I have select:
SELECT hz FROM my_tablw WHERE id=1
It return me 1 row and 1 column:
hz
some data
I have
@Autowired
private NamedParameterJdbcTemplate jdbcTemplate;
And I need make query and return 1 row - String some data
.
I create
jdbcTemplate.query("SELECT hz FROM my_tablw WHERE id=:id", insertManagerParameters, (rs, rowNum) -> {
if (rs.next()) {
return rs.getString(1);
}
return "";
});
but this method return List<String>
Upvotes: 4
Views: 9088
Reputation: 976
I would use the queryForObject
method, like:
jdbcTemplate.queryForObject("SELECT hz FROM my_tablw WHERE id=:id", insertManagerParameters, String.class);
Which should return a String
with the query results.
Upvotes: 5
Reputation: 1
MapSqlParameterSource paramSource = new MapSqlParameterSource();
paramSource.addValue("id", id);
return this.customNamedParameterJdbcTemplate.getNamedParameterJdbcTemplate().queryForObject(sqlConsultarPorId, paramSource,new MapeoReserva());
Upvotes: 0