我正在制作一个参数输入表单来查询审计表。不需要输入。
下面的 SQL 查询是我希望 Java 解析的,它运行良好。它根据输入返回我想要的行。
SELECT *
FROM _audit
WHERE DATEDIFF(NOW(), `_audit_timestamp`) < 30
AND (('smith' <> '' AND _action__user = 'smith')
OR (_action__user = _action__user AND 'smith' IS NULL))
AND ((NULL IS NOT NULL AND _action_searchkey IS NULL)
OR (_action_searchkey = _action_searchkey OR _action_searchkey IS NULL))
AND ((NULL IS NOT NULL AND _action_customer IS NULL)
OR (_action_customer = _action_customer AND _action_customer IS NULL))
ORDER BY _audit_timestamp DESC
但是,当我尝试让它在 Java 中工作时,它根本不返回任何行。我认为这与地图中的值有关。在调试器中查看它们,它显示“”而不是 NULL
String sqlText = "SELECT * "
+ " FROM _audit "
+ " WHERE DATEDIFF(NOW(), `_audit_timestamp`) < :days "
+ " AND ((:Name IS NOT NULL AND _action__user = :Name) "
+ " OR (_action__user = _action__user AND :Name IS NULL)) "
+ " AND ((:SearchKey IS NOT NULL AND _action_searchkey = :SearchKey) "
+ " OR (_action_searchkey = _action_searchkey AND :SearchKey IS NULL)) "
+ " AND ((:Customer IS NOT NULL AND _action_customer = :Customer) "
+ " OR (_action_customer = _action_customer AND :Customer IS NULL)) "
+ " ORDER BY _audit_timestamp DESC";
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("days", aqForm.getDays().toString());
parameters.put("Name", aqForm.getName());
parameters.put("SearchKey", aqForm.getSearchKey());
parameters.put("Customer", aqForm.getCustomer());
我在这里吠错树了吗?