如果我有一个Java Date,并且使用JDBCTEmplate我想在预准备语句中使用它,这是正确的语法吗?
Date x = new Date();
...
String SQL = "select a.1, a.2 from b JOIN a ON b.id = a.b_id where b.name = ? and a.type = ? and a.date = ?";
A istance = jdbcTemplate.queryForObject(SQL, new Object[]{variable_1, variable_2, x}, new aAndbMapper());
或者我应该写:
String SQL = "select a.1, a.2 from b JOIN a ON b.id = a.b_id where b.name = ? and a.type = ? and DATE(a.date) = ?";
答案 0 :(得分:1)
第一个是一个不错的选择,但我会在没有自定义映射器的情况下完成:
String SQL = "select a.1, a.2 from b JOIN a ON b.id = a.b_id where b.name = ? and a.type = ? and a.date = ?";
A istance = getJdbcTemplate().queryForObject(SQL, new Object[]{variable_1, variable_2, x}, new BeanPropertyRowMapper(A.class));
有关beanPropertymapper的更多信息:Documentation