如何在使用UCanAccess JDBC驱动程序时检查日期/时间的NULL值?

时间:2015-12-13 16:44:23

标签: ms-access jdbc ucanaccess

使用UCanAccess JDBC驱动程序访问MS Access DB时,我在处理Date时面临太多问题。我想检查日期/时间字段是否为空。如果有Null然后想要更新,但我不能这样做。 字段'logout_time'是MSAccess数据库中的'日期/时间'数据类型。

update user_Log set logout_time = #12/13/2015 10:33:28# where (user_Id =3) & (logout_time = NULL);

这将发送sqlString

    net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::3.0.3 incompatible data types in combination 
 This exception may  happen if you add integers representing units of time directly to datetime values using the arithmetic plus operator but without specifying the unit of date. 
   In this specific case you have to use, for example, <dateColumn> + 1 DAY.
    at net.ucanaccess.jdbc.UcanaccessStatement.executeUpdate(UcanaccessStatement.java:222)

此SQL语句从MSAccess Query执行得很好。但它无法从UCa​​nAccess JDBC Driver执行。它会产生错误:

{{1}}

1 个答案:

答案 0 :(得分:2)

  

此SQL语句可以从MSAccess Query中很好地执行。

不是真的。它可能会执行,但它也可能无法执行您想要的操作。你的代码......

WHERE ... (logout_time = NULL)

...是非标准SQL,可能会产生意外结果(详情here)。你想要

WHERE ... (logout_time IS NULL)

您还应该停止使用动态SQL ,而是使用PreparedStatement参数化查询来执行更新。