查询postgres select不返回结果?

我正在开发一个Java应用程序,并使用resultset。我写这个查询,它的工作原理,我得到的结果

SELECT * 
FROM BD 
WHERE 
    CAST(parent_id AS integer) = " + (Integer.parseInt(arrHeading[0])) + " 
    AND CAST(section AS double precision) = " + Double.parseDouble(arrHeading[1]) + "";

arrHeading is type string, but when I write the query below it does not return any results. cas is type character varying(12). I am having trouble because it's a character, and I dont know why I am not getting any result. I tried with the quotes but still does not work. Any ideas?

SELECT * 
FROM BD 
WHERE 
    CAST(parent_id AS integer) = " + (Integer.parseInt(arrHeading[0])) + " 
    AND CAST(section AS double precision) = " + Double.parseDouble(arrHeading[1]) + "
    AND cas = '" + arrHeading[2] + "'";
0
额外 编辑
意见: 2

1 答案

我会建议首先将arrHeading [2]替换为查询中的实际值,即hardcode cas =“'your valiue'”,并查看查询是否返回任何结果

0
额外
我替换为SELECT * FROM BD WHERE CAST(parent_id AS integer)=“+(Integer.parseInt(arrHeading [0]))+”AND CAST(section double double precision)=“+ Double.parseDouble(arrHeading [1]) +“AND cas ='”+“B1”+“'”;我得到结果
额外 作者 bentham,
它打印B1,它是一个字符串
额外 作者 bentham,
我得到了SELECT * FROM BD WHERE CAST(parent_id AS integer)= 19 AND CAST(AS双精度部分)= 1665.0 AND cas ='B1'
额外 作者 bentham,
是的,这是为了一个额外的空白空间,谢谢我没有注意到
额外 作者 bentham,
看起来arrHeadin [2]有一个额外的空格,使用arrHeading [2] .trim()
额外 作者 coder,
@bentham - 打印什么 arrHeading [2] 显示?
额外 作者 dezso,
@bentham - 如果你打印你的查询字符串?
额外 作者 dezso,