查询避免Unknown column ‘xxx’ in ‘where clause

    科技2022-07-13  126

    在项目中连接数据库的时候出现了上述错误, 原因是:sql语句后面where中的判断语句如何是字符型的话需要加单引号

    例如: String sql=“select age from user where name=”+xxx+"; 设置name的值为columName,则错误如下: Unknown column 'xxx′ in ‘where clause’ 解决步骤: sql中如果name是整型的倒不会出现什么错误,而如果sql中字符串类型必须要包含在引号内。 所以修改sql为String sql="select age from user where name=’"+xxx+"’"; 则错误消失。

    Processed: 0.013, SQL: 8