zoukankan      html  css  js  c++  java
  • mybatis 中文做参数报错

      一个简单的查询,如果参数中有中文。如下:

    <select id="xxxx" resultType="hashmap">
        select * from talbe_a a where  a.kpeople = ${name}
    </select>

    报错:

    org.apache.ibatis.exceptions.PersistenceException: 
    ### Error querying database.  Cause: java.sql.SQLSyntaxErrorException: ORA-00904: "萧亚轩": 标识符无效
    ...

    Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "萧亚轩": 标识符无效
    ....

    mybatis sql日志:

    18:06:36,192 DEBUG JdbcTransaction:47 - Openning JDBC Connection
    18:06:36,830 DEBUG PooledDataSource:47 - Created connection 1459361227.
    18:06:36,843 DEBUG queryrealactormediatop:47 - ooo Using Connection [oracle.jdbc.driver.T4CConnection@56fc15cb]
    18:06:36,843 DEBUG queryrealactormediatop:47 - ==>  Preparing: select * from table_a a where v1.kpeople = 萧亚轩 
    18:06:36,961 DEBUG queryrealactormediatop:47 - ==> Parameters: 

    注意:“萧亚轩”两边没有单引号,不是“?”的占位符,参数列表里面是没有值。

    修改其实很简单:

    v1:换$ 为#

    <select id="xxxx" resultType="hashmap">
        select * from talbe_a a where  a.kpeople = #{name}
    </select>

    v2:添加 ‘’ 单引号

    <select id="xxxx" resultType="hashmap">
        select * from talbe_a a where  a.kpeople = ‘${name}‘
    </select>

    #只会当成个字符串

    $就不一定是字符串,或者其他类型

  • 相关阅读:
    elasticsearch安装教程
    mysql设置账号密码及授权
    mongodb设置账号密码授权案例
    新安装的centos 6.5,不能上网,外网ping不通,内网可以ping通解决方法
    docker-compose安装教程
    解决github图片不显示问题
    网站宽带计算方式
    thinkphp 如何实现url的rewrite
    nginx Https配置
    Ext.Net导入Excel
  • 原文地址:https://www.cnblogs.com/Springmoon-venn/p/6857705.html
Copyright © 2011-2022 走看看