[英]Postgresql : syntax error at and near null
I have a web application that is connected to postgresql.我有一个连接到 postgresql 的 web 应用程序。 I'm trying to get data from the database with a prepared statement and continuously get syntax error at or near null.
我正在尝试使用准备好的语句从数据库中获取数据,并在 null 或其附近不断出现语法错误。
Following is my code snippet for query:以下是我的查询代码片段:
PreparedStatement pstmt = conn.prepareStatement("SELECT * "+ "FROM rooms1 o " + "JOIN rooms2 op" +
" ON o.room_id = op.room_id " +"JOIN rooms3 p " +
" ON op.person_id = p.person_id " +
"WHERE o.room_id = ? " +
" ORDER BY o.plate_order ASC;")) {
//Rest of code
this query works fine when check on test database but when use it inside prepared statement it gives error as这个查询在检查测试数据库时工作正常,但是当在准备好的语句中使用它时,它会给出错误
Caused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near "null"
position: 54
From some research I think that problem is with my query, also this is my first time writing Postgresql queries.根据一些研究,我认为问题出在我的查询上,这也是我第一次编写 Postgresql 查询。 please have look at it.
请看一下。
o.room_id =? o.room_id =? if?
如果? is null so u have to check "o.room_id is null".
是 null 所以你必须检查“o.room_id 为空”。 u can check this with inline if
如果你可以用内联检查这个
I have indicated the error position 54 with ***
:我用
***
指出了错误 position 54 :
SELECT * FROM rooms1 o
JOIN rooms2 op ON o.room_id = ***op.room_id
JOIN rooms3 p ON op.person_id = p.person_id
WHERE o.room_id = ?
ORDER BY o.plate_order ASC
I do not entirely understand the error message but op.room_id perhaps has null occurrences.我不完全理解错误消息,但 op.room_id 可能有 null 出现。
Weird error IMHO, but try a LEFT JOIN奇怪的错误恕我直言,但尝试 LEFT JOIN
SELECT o.*, op.*, p.* FROM rooms1 o
LEFT JOIN rooms2 op ON o.room_id = op.room_id
LEFT JOIN rooms3 p ON op.person_id = p.person_id
WHERE o.room_id = ?
ORDER BY o.plate_order ASC
(The semicolon ;
at the end is superfluous.) (分号
;
结尾是多余的。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.