如果我有一个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) = ?";
发布于 2017-08-24 12:52:17
第一个是一个很好的选择,不过我会在没有自定义映射器的情况下这样做:
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
https://stackoverflow.com/questions/45859310
复制相似问题