我正在使用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)
任何想法为什么? 我很绝望..
答案 0 :(得分:2)
IS NOT
和IS
用于NULL值。使用<>
或NOT a = b
作为值。
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;