How to Solve Mybatis Chinese parameter error

A simple query, if there is Chinese in the parameters. As follows:

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

Error reporting:

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.sql.SQLSyntaxErrorException: ORA-00904: "Xiao Yaxuan": Identifier is invalid
...

Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "Xiao Yaxuan": Identifier is invalid
....

mybatis sql log

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:

Note: “Xiao Yaxuan” has no single quotation marks around it, not “?” There is no value in the parameter list

 

The modification is actually very simple:

V1: change $to#

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

V2: Add ” single quotation mark

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

#It’s just a string

$is not necessarily a string or other type

Similar Posts: