您的位置:首页 > 编程语言 > Java开发

解决java传递参数是String类型,pgsql的numeric字段接收报错问题

2017-08-18 16:41 886 查看
postgresql对传入的参数类型匹配相当严格

如select * from user where id = #id#

假设id类型为numeric,而传入的id为string的话postgresql就会报错:

--- Cause: org.postgresql.util.PSQLException: ERROR: operator does not exist: numeric = character varying

  建议:No operator matches the given name and argument type(s). You might need to add explicit type
 casts.
  位置:125
Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: numeric = character varying
  建议:No operator matches the given name and argument type(s). You might need to add explicit type
 casts.

暂时想到的解决方法:

select * from user where id = cast(#id# as numeric)

如果哪位大神有更好的方法请告知!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java postgresql