MySql异常:Unknown column ‘XXX’ in Where Clause Error
具体异常:
Error updating database. Cause: java.sql.SQLSyntaxErrorException: Unknown column '8b3b12e118a14698b8df4141ea1a7e5a' in 'where clause';
引发原因:
- 拼凑SQL语句时没有将字符类型数据包含在引号中或是用`包含了(单从异常字面意思来理解佷容易以为是列名导致的错误)
- 事实上也可能是SQL语句中列名写错了(即与数据库表中字段名不对应,往往是将驼峰命名的类属性当成了表字段)
实例:
实例一
发生异常的代码
<where>
<if test="numId != null">AND num_id = ${numId}</if>
</where>
异常解决方法:
方法一
<where>
<if test="numId != null">AND num_id = '${numId}'</if>
</where>
方法二
<where>
<if test="numId != null">AND num_id = #{numId}</if>
</where>
实例二
发生异常的代码:
processInstanceId = #{processInstanceId}
异常解决方法:
AND process_instance_id = #{processInstanceId}