I'm working on an Java application with SQLite database. I have to execute this query :
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;
This works well in SQLiteStudio, but in my application I got this exception :
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
o开发者_C百科rg.sqlite.Conn.prepareStatement(Conn.java:231) at
org.sqlite.Conn.prepareStatement(Conn.java:224) at
org.sqlite.Conn.prepareStatement(Conn.java:213)
Any Idea why ? I'm desperate ..
IS NOT
and IS
is used for NULL values. Use <>
or NOT a = b
for values.
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;
精彩评论