我正在开发一个带有 SQLite 数据库的 Java 应用程序。我必须执行这个查询:
select * from service
where (tache IS NOT 'I')
AND (idequiv IS null OR idequiv = '' OR idequiv<=0)
union
select * from service where (idequiv IS NOT null)
and (tache IS NOT 'I')
group by num_service
order by num_service;
这在 SQLiteStudio 中运行良好,但在我的应用程序中我遇到了这个异常:
java.sql.SQLException: near "'I'": syntax error at
org.sqlite.DB.throwex(DB.java:288) at
org.sqlite.NativeDB.prepare(Native Method) at
org.sqlite.DB.prepare(DB.java:114) at
org.sqlite.PrepStmt.<init>(PrepStmt.java:37) at
org.sqlite.Conn.prepareStatement(Conn.java:231) at
org.sqlite.Conn.prepareStatement(Conn.java:224) at
org.sqlite.Conn.prepareStatement(Conn.java:213)
知道为什么吗? 我很绝望..
最佳答案
IS NOT
和IS
用于 NULL 值。使用<>
或NOT a = b
对于值(value)观。
SELECT * FROM service
WHERE (NOT tache = 'I')
AND (idequiv IS null OR idequiv = '' OR idequiv<=0)
UNION
SELECT * FROM service
WHERE (idequiv IS NOT null)
AND (NOT tache = 'I')
GROUP BY num_service
ORDER BY num_service;
关于java - "IS NOT"Java/SQLite 应用程序中的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6826546/