基本查询方法
JdbcTemplate 中可用的一些 queryFor *方法对执行 CRUD 操作的简单 sql 语句很有用。
查询日期
String sql = "SELECT create_date FROM customer WHERE customer_id = ?";
int storeId = jdbcTemplate.queryForObject(sql, java.util.Date.class, customerId);
查询整数
String sql = "SELECT store_id FROM customer WHERE customer_id = ?";
int storeId = jdbcTemplate.queryForObject(sql, Integer.class, customerId);
要么
String sql = "SELECT store_id FROM customer WHERE customer_id = ?";
int storeId = jdbcTemplate.queryForInt(sql, customerId); //Deprecated in spring-jdbc 4
查询字符串
String sql = "SELECT first_Name FROM customer WHERE customer_id = ?";
String firstName = jdbcTemplate.queryForObject(sql, String.class, customerId);
查询列表
String sql = "SELECT first_Name FROM customer WHERE store_id = ?";
List<String> firstNameList = jdbcTemplate.queryForList(sql, String.class, storeId);