java - 使用 Spring jdbcTemplate 更新 MS Access 中的日期

标签 java spring ms-access jdbctemplate

我正在使用 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/

相关文章:

java - 在 Android 应用程序的 Eclipse 中构建工作区遇到问题

java - 启动@Async : what is best way to create 1000 no of threads using spring

java - tomcat不支持major.minor版本52.0

ms-access - VBA 等到表单打开

javascript - 在 Java 中,如何在执行页面上的 Javascript 后访问更新的 HTML 源代码?

java - Java 中的 HTTP 服务

java - 如何在java中的For循环中将此跳过保留在内存中GoTo Next Iteration

java - 使用 Project Reactor 并行调用其余 Web 服务?

excel - 如果将重复记录插入表中, Access 不会引发错误

ms-access - Access/VBA 如何处理除以 null?