Java SQLSyntaxErrorException: Unknown column 'ci.user_id' in 'where clause' - 解决方法
Error querying database. Cause: java.sql.SQLSyntaxErrorException: Unknown column 'ci.user_id' in 'where clause' ### The error may exist in file [C:\project\zhongxin\CiticMetal-Backend\customer\customer-biz\target\classes\mapper\CustomerInfoMapper.xml] ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: SELECT COUNT(*) FROM (SELECT ci.customer_id, ci.customer_name, ci.cbmm_cgs_name, ci.customer_type, ci.update_time FROM cm_customer_info ci WHERE ci.del_flag = '0' AND (ci.user_id = ? OR ci.user_id IS NULL) GROUP BY ci.customer_id) TOTAL ### Cause: java.sql.SQLSyntaxErrorException: Unknown column 'ci.user_id' in 'where clause' ; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: Unknown column 'ci.user_id' in 'where clause'
报错原因分析以下内容:报错信息显示在执行SQL语句时出现了错误,具体原因是在WHERE子句中使用了未知的列名'ci.user_id'。根据错误提示信息,错误可能出现在C:\project\zhongxin\CiticMetal-Backend\customer\customer-biz\target\classes\mapper\CustomerInfoMapper.xml文件中的defaultParameterMap中。
根据错误提示信息和SQL语句分析,发现在查询语句中使用了别名ci来表示cm_customer_info表,在WHERE子句中使用了ci.user_id作为过滤条件。然而,数据库中并不存在名为ci.user_id的列,导致查询失败。
解决方法是检查数据库表cm_customer_info中是否存在user_id列,并确认列名是否正确。如果列名正确但仍然报错,可能是数据库表结构发生了变化,需要更新映射文件CustomerInfoMapper.xml中的SQL语句,确保查询语句与数据库表结构一致。
原文地址: https://www.cveoy.top/t/topic/qhn7 著作权归作者所有。请勿转载和采集!