日期:2014-05-16 浏览次数:20417 次
public List<Customer> findCustomerByName(String name) { String sql = "select id,name,age from customers where name=?"; return jdbcTemplate.query(sql, new Object[]{name}, new RowMapper(){ public Object mapRow(ResultSet rs, int rowNum) throws SQLException { Customer customer = new Customer(); customer.setId(rs.getInt("id")); customer.setName(rs.getString("name")); customer.setAge(rs.getInt("age")); return customer; }}); }
public List<Customer> findCustomerByName(String name) { String sql = "select id,name,age from customers where name=:name"; Map<String, Object> map = new HashMap<String, Object>(); map.put("name", name); return jdbcTemplate.query(sql, map, new RowMapper(){ public Object mapRow(ResultSet rs, int rowNum) throws SQLException { Customer customer = new Customer(); customer.setId(rs.getInt("id")); customer.setName(rs.getString("name")); customer.setAge(rs.getInt("age")); return customer; }}); }
String sql = "select id,name,age from customers where name=?"; return jdbcTemplate.query(sql, new ParameterizedRowMapper<Customer>(){ public Customer mapRow(ResultSet rs, int rowNum) throws SQLException { Customer customer = new Customer(); customer.setId(rs.getInt("id")); customer.setName(rs.getString("name")); customer.setAge(rs.getInt("age")); return customer; }}, name);