[英]updating date in MS Access using Spring 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 });
在此先感謝,Santhosh
Date
是Jet(Access數據庫引擎)中的關鍵字,因此需要用方括號“轉義”。 同樣,日期文字由#
分隔。 我對Java不太熟悉,無法確定您的日期是否采用這種格式。
無論如何,您的sql字符串必須是這樣的:
"update timesheet set [date]=#4/5/2011# where task_id=20"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.