[英]org.postgresql.util.PSQLException - 2019
I am trying to automate my API & DB testing(postgresql) via Cucumber(Java).我正在尝试通过 Cucumber(Java)自动化我的 API 和 DB 测试(postgresql)。 How ever i have written my code and trying to execute below queries:我是如何编写代码并尝试执行以下查询的:
resultSet=statement.executeQuery("select * from rules_data.postcode_leadtime where postcode = "+postcodedistrict.toUpperCase()+" and order_type = "+ordertype.toUpperCase()+"");
Now, if i run the direct query ie -现在,如果我运行直接查询,即 -
select *
from rules_data.postcode_leadtime
where postcode = 'MK9'
and order_type = 'ADSI'
it runs perfectly fine but when I run the above query with parameters it gives the below error:它运行得很好,但是当我使用参数运行上面的查询时,它给出了以下错误:
org.postgresql.util.PSQLException: ERROR: column "mk9" does not exist org.postgresql.util.PSQLException:错误:列“mk9”不存在
I googled this up, found out that it has to be in Uppercase when executing the command, so then i made sure that its being converted into uppercase as you can see in the parameter in the above query, BUT STILL I AM GETTING THE SAME ISSUE.我用谷歌搜索了一下,发现在执行命令时它必须是大写的,所以我确保它被转换成大写,正如你在上面查询的参数中看到的那样,但我仍然遇到同样的问题. Happening for my other commands too.我的其他命令也发生了。
Note: I have tried printing the values of parameters, they are coming in Upper cases.注意:我尝试打印参数值,它们以大写形式出现。
Another issue i am getting is with the below query:我遇到的另一个问题是以下查询:
resultSet=statement.executeQuery("select day from rules_data.hub_workdays where hub_id = " + hub + " and available = 'N'");
Over here hub is an integer value, it is coming fine on printing but when executing via Java gives an error below:这里的集线器是一个整数值,它在打印时很好,但是当通过 Java 执行时会出现以下错误:
org.postgresql.util.PSQLException: ERROR: operator does not exist: character varying = integer org.postgresql.util.PSQLException:错误:运算符不存在:字符变化=整数
But when i run with value it works fine.但是当我以价值运行时,它工作正常。
select day
from rules_data.hub_workdays
where hub_id = '593'
and available = 'N'
Already mentioned in my first explanation.在我的第一个解释中已经提到。
You should really use PreparedStatement
as written in the comment, but your error can go away with the following fix:您应该真正使用注释中所写的PreparedStatement
,但是您的错误可以通过以下修复消失:
resultSet=statement.executeQuery("select * from rules_data.postcode_leadtime
where postcode = '"+postcodedistrict.toUpperCase()+"'
and order_type = '"+ordertype.toUpperCase()+"'");
basically you need to add single quotes so that the parameters become strings
基本上你需要添加单引号,以便参数成为strings
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.