1

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

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

4

1 回答 1

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;
于 2011-07-26T07:18:12.853 回答