我正在使用 MS Access 和 Spring Jbdc 模板。
如果我尝试使用 jdbctemplate 更新表中的日期,则会出现错误
"Caused by: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement."
这是代码:
Calendar cal = Calendar.getInstance();
java.sql.Date sqlDate = new java.sql.Date(cal.getTime().getTime());
JdbcTemplate jdbcTemplate = new JdbcTemplate(ds);
int id = jdbcTemplate
.queryForInt("select TASK_ID from timesheet where task_id=1");
jdbcTemplate.update("update timesheet set date=? where task_id=20",
new Object[] { sqlDate });
提前致谢, 桑托什
最佳答案
Date
是 Jet(Access 数据库引擎)中的关键字,因此需要用方括号对其进行“转义”。此外,日期文字由 #
分隔。我对 Java 不太熟悉,不知道您的日期是否是这样格式化的。
无论如何,您的 sql 字符串都需要是这样的:
"update timesheet set [date]=#4/5/2011# where task_id=20"
关于java - 使用 Spring jdbcTemplate 更新 MS Access 中的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5555929/