0

I am trying to use Java SQL namedParameterJdbcTemplate to get a List of ID Numbers.

private static final String Customer_Query = "SELECT Customer_Id From dbo.Customers WHERE Customer_Name = :Customer_Name";

MapSqlParameterSource customer_parameters = new MapSqlParameterSource();
customer_parameters.addValue( "Customer_Name", "Joe");

List<Long> Customer_Id =  namedParameterJdbcTemplate.query(Customer_Query, customer_parameters);

Error: Cannot resolve method 'query(java.lang.String, org.springframework.jdbc.core.namedparam.MapSqlParameterSource)'

This resource gets the Whole Table row, I just need one column. How can this be done?

NamedParameterJdbcTemplate - Select * from

Trying to be efficient in querying for performance tuning and acquiring data, there are lot of sql columns in the table .

mattsmith5
  • 540
  • 4
  • 29
  • 67
  • There is no `query` method on [`NamedParameterJdbcTemplate`](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplate.html) that only takes a `String` and a `SqlParameterSource`. You probably wanted to call `queryForList`, but that won't produce a `List` like this. Also, the question you link also uses a `RowMapper`, which is absent from yours. – Mark Rotteveel Aug 22 '21 at 07:51
  • hi @MarkRotteveel, I don't need a rowmapper, is there any way around this? what is the proposed solution? thanks – mattsmith5 Aug 22 '21 at 08:01
  • I don't normally use JdbcTemplate, but either you'll need a RowMapper, or you could try if passing `Long.class` as the third parameter to `queryForList` does the trick. See the duplicate (which is for `List`, but that should basically be the same). – Mark Rotteveel Aug 22 '21 at 08:03
  • we need to reopen, this proposed solution is NOT for namedParameterJbdcTemplate, only regular https://stackoverflow.com/questions/13354158/how-to-query-for-a-liststring-in-jdbctemplate @MarkRotteveel – mattsmith5 Aug 22 '21 at 20:59

0 Answers0