开发者

updating date in MS Access using Spring jdbcTemplate

开发者 https://www.devze.com 2023-02-22 01:12 出处:网络
I\'m using MS Access and Spring Jbdc Template. Where If I try to update the date in t开发者_如何学Cable using jdbctemplate it giving me error

I'm using MS Access and Spring Jbdc Template.

Where If I try to update the date in t开发者_如何学Cable using jdbctemplate it giving me error

"Caused by: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement."

This is the code:

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 });

Thanks in Advance, Santhosh


Date is a keyword in Jet (the Access db engine) so it needs to be "escaped" with square brackets. Also, date literals are delimited by #'s. I'm not familiar enough with Java to know if your date is being formatted that way.

In any case, your sql string needs to be something like this:

"update timesheet set [date]=#4/5/2011# where task_id=20"
0

精彩评论

暂无评论...
验证码 换一张
取 消