Java / SQLite应用程序中的“IS NOT”语法错误

时间:2011-07-26 07:16:06

标签: java sqlite sqlexception

我正在使用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)

任何想法为什么? 我很绝望..

1 个答案:

答案 0 :(得分:2)

IS NOTIS用于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;