com.highgo.jdbc.util.PSQLException: 错误: 操作符不是唯一的: integer = character varying(mybatis postgreSql)

1545年前 (2021-05-11)瀚高数据库4247

postgresql抛出的异常,是因为数据库类型是int类型,而java传参String造成。有2种解决方案,建议第二种方案更方便简洁

image.png

解决方案一:

代码

public int deleteSysUserSignByIds(String ids) {
    return sysUserSignMapper.deleteSysUserSignByIds(Convert.toStrArray(ids));
}

XML:

<delete id="deleteSysUserSignByIds" parameterType="String">
    delete from sys_user_sign where id in
    <foreach item="id" collection="array" open="(" separator="," close=")">
        #{id}
    </foreach>
</delete>

而数据库的id类型是int类型

修改方案:

public int deleteSysUserSignByIds(String ids) {
    return sysUserSignMapper.deleteSysUserSignByIds(Convert.toLongArray(ids));
}

传入的string数组转换为integer数组或者long数据即可。

当然对应接口方法的接收参数类型也要做相应改变。

解决方案二:(只需修改下xml文件)

解决方案是在xml内将string类型的参数变量 强转为int类型,在变量后加::int

<delete id="deleteGoodsRecordByIds" parameterType="String">
    delete from goods_record where id in
    <foreach item="id" collection="array" open="(" separator="," close=")">
        #{id}::int
    </foreach>
</delete>


本文原创,转载必追究版权。

分享给朋友:

相关文章

Oracle sql优化

 一、问题的提出 在应用系统开发初期,由于开发数据库数据比较少,对于查询SQL语句,复杂视图的的编写等体会不出SQL语句各种写法的性能优劣,但是如果将应用系统提交实际应用后,随着数据库中数据...

Oracle 数据库cmd命令备份

 //导出exp wsbspt/wsbspt@192.168.1.101/wsbs file=D:/wsbspt.dmp log=D:/wsbspt.txt//导入imp &nbs...

org.tigris.subversion.javahl.ClientException:Attempted to lock an already-locked dir

 svn更新或提交时候报错:org.tigris.subversion.javahl.ClientException:Attempted to lock an already-locke...

java解析JSON 数组数据 实例

 public  static void main (String args[]){  String sJson ="[{'acceptTim...

get/post方式调用http接口

get/post方式调用http接口

 1. 项目环境如下:myeclipse8.5 、tomcat5.0/weblogic、xp、JDK:开发1.5,编译1.4为了方便,在原来的web项目UpDown中新建了一个httpcal...

freeMarker Jfinal 获取session里的值

问题:freeMaker session取值的常用格式都试过 session["xxx"],session.xxx 直接xxx 都取不出来?????解决:JFinal与Struts...

评论列表

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。