[英]How to specify parameters in an SQL query using spring's jdbcTemplate
How would i specify the value for the 'age' parameter in the following jdbctemplate example? 我如何在以下jdbctemplate示例中指定'age'参数的值?
String sql = "SELECT * FROM CUSTOMER where age = ? ";
List<Customer> customers = new ArrayList<Customer>();
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
List<Map> rows = jdbcTemplate.queryForList(sql);
for (Map row : rows) {
Customer customer = new Customer();
customer.setCustId((Long)(row.get("CUST_ID")));
customer.setName((String)row.get("NAME"));
customer.setAge((Integer)row.get("AGE"));
customers.add(customer);
}
return customers;
You would use the queryForList() method taking arguments as argument, for example: 您可以使用queryForList()方法将参数作为参数,例如:
List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql, theAge);
Learn to read API documentation (and documentation in general). 学习阅读API文档(以及一般文档)。 That's how you learn. 这就是你学习的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.