gpt4 book ai didi

java - PostgreSQL 查询总是返回真

转载 作者:行者123 更新时间:2023-11-29 14:19:37 25 4
gpt4 key购买 nike

我有一个必须返回 boolean 值的查询,但我总是得到相同的结果。我试过这个:

 boolean exist=stmt.execute("select exists(select 1 from calcul where 
to_char(date, 'YYYY-MM')=to_char("+dates+", 'YYYY-MM') AND
idproduit="+codeP+" AND ppa="+PPA+" AND tr="+TR+" AND net="+NET+" AND
dateper='"+datePer+"')");

结果总是true,永远不会是false;为什么?

最佳答案

true 只是表示有一个结果,如 execute() 的 javadoc 中所述:

Returns:
true if the first result is a ResultSet object; false if the first result is an update count or there is no result.

您需要调用getResultSet()以获得实际结果。

关于java - PostgreSQL 查询总是返回真,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33881147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com