NutzCN Logo
问答 nutz qurey 方法有时会报错sql查询错误,项目里好几个地方出现了,有时候又不报错,放在Navicat Premium不报错
发布于 1820天前 作者 hryc 1452 次浏览 复制 上一个帖子 下一个帖子
标签:

nutz qurey 方法有时会报错sql查询错误,项目里好几个地方出现了,有时候又不报错,放在Navicat Premium不报错:

Caused by: java.sql.SQLException: No operations allowed after statement closed.

请求异常:!Nutz SQL Error: 'SELECT c.*,i.participantsNum as participantsNum,s.electiveType FROM course c LEFT JOIN course_info i ON i.courseId= c.id LEFT JOIN course_study s ON c.id=s.courseId and s.delFlag=0 WHERE c.delFlag=false AND c.createSource='1' AND c.state='1' AND c.auditState='1' AND c.shopId='pn5rf8p7vuihorp8vqkrkccpqq' AND c.classifyId='7601e5c4cd3741778d0aaf80edbf8a30' GROUP BY c.id ORDER BY c.createAt DESC LIMIT 0, 10' PreparedStatement: 'SELECT c.*,i.participantsNum as participantsNum,s.electiveType FROM course c LEFT JOIN course_info i ON i.courseId= c.id LEFT JOIN course_study s ON c.id=s.courseId and s.delFlag=0 WHERE c.delFlag=? AND c.createSource=? AND c.state=? AND c.auditState=? AND c.shopId=? AND c.classifyId=? GROUP BY c.id ORDER BY c.createAt DESC LIMIT 0, 10' CaseMessage=No operations allowed after statement closed.

4 回复
@Override
    public Pagination queryCourse(CourseQuery queryVo) {
        Cnd cnd=this.getQueryCnd(queryVo);
        Sql sql = dao().execute(Sqls.create("SELECT  c.*,i.participantsNum as participantsNum,s.electiveType FROM course c " +
                " LEFT JOIN course_info i ON i.courseId= c.id LEFT JOIN course_study s ON c.id=s.courseId and s.delFlag=0  $condition").setCondition(cnd));
        Pagination pagination = listPage(queryVo.getPage(), queryVo.getLimit(), sql, CourseVo.class);
        List<CourseVo> list=(List<CourseVo>) pagination.getList();
        if (list!=null && list.size()>0){
            for (CourseVo vo:list){
                //主讲老师名称
                String teacherStr="";
                List<CourseRel> teacherRelList=courseRelService.query(CndUtil.getCnd().and("courseId","=",vo.getId()).and("relType","=",CourseRelTypeEnum.TEACHER.getKey()));
                if (teacherRelList!=null && teacherRelList.size()>0){
                    for (CourseRel rel:teacherRelList){
                        Teacher teacher= teacherService.fetch(rel.getRelId());
                        if (teacher!=null){
                            teacherStr+=teacher.getTeacherName()+",";
                        }
                    }
                }
                vo.setTeacherIdStr(teacherStr);
            }
        }
        return pagination;
    }

代码是这样的 @wendal

既然是有时候行有时候不行,你得总结规律,稳定重现,才能找到问题

逻辑上:
group BY c.id

,i.participantsNum as participantsNum,s.electiveType
冲突。
如果凑巧, participantsNum ,electiveType 里的值为0个或1个是在不严格的MYSQL是对的。
但如果不是0,1个就OVER

添加回复
请先登陆
回到顶部