2
如果我有一個Java Date,並且使用JDBCTEmplate,我想在準備好的語句中使用它,這是正確的語法嗎?如何在Spring Prepared Statement中傳遞Java日期
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) = ?";
第一個是我的更好的解決方案 – Jens
使用'java.sql.Date'類的對象作爲參數 – Zico