“不是” Java / SQLite 应用程序中的语法错误

发布于 2024-11-26 00:08:55 字数 813 浏览 0 评论 0原文

我正在开发一个带有 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)

知道为什么吗? 我很绝望..

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
 org.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 ..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

椵侞 2024-12-03 00:08:55

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;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文