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' \n前端报错,\n\n======= Sql Logger ======================\nselect 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 = 1646326606744612866 or ci.user_id is null) group by ci.customer_id ) TOTAL\n======= Sql Execute Time: 0ms =======\nidea控制台没有报错但是sql执行0ms\n\n但是idea控制台的sql语句在数据库执行查询没有问题可以出数据\n,分析一下内容:根据错误信息,可以看到SQL语句中的ci.user_id这个列不存在,因此在执行查询时会报错。根据错误信息,错误出现在C:\project\zhongxin\CiticMetal-Backend\customer\customer-biz\target\classes\mapper\CustomerInfoMapper.xml文件中的defaultParameterMap。根据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,可以看到在子查询中使用了ci.user_id这个列,但是该列在数据库中不存在。\n\n解决这个问题的方法是确保数据库中的表cm_customer_info中有user_id这个列,并且列名拼写正确。如果确实没有这个列,需要修改SQL语句或者数据库表结构,以确保查询语句正确执行。

Java.sql.SQLSyntaxErrorException: Unknown column 'ci.user_id' in 'where clause' - 解决方法

原文地址: https://www.cveoy.top/t/topic/qho6 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录