4

在以下 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;
4

1 回答 1

6

您将使用将参数作为参数的queryForList()方法,例如:

List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql, theAge);    

学习阅读 API 文档(和一般文档)。你就是这样学习的。

于 2012-06-10T17:35:36.760 回答