zoukankan      html  css  js  c++  java
  • 困惑

            StringBuffer recordSql = new StringBuffer(200);
            
            recordSql.append(" update DeviceAlarmOperateInfo a set a.description = :msg where 1 = 1 ");
            
            if (orgCode != null && !"".endsWith(orgCode)) {
                recordSql.append(" and a.deviceinfo.organization.orgzCode like :orgCode ");
            }
            
            recordSql.append(" and a.modifiedUser = null ");
    
            recordSql.append(" and a.currentstatus <> 0 ");
    
            recordSql.append(" and a.operatetime >= :startDate ");
    
            recordSql.append(" and a.operatetime < :endDate ");
    
            Query recordQuery = em.createQuery(recordSql.toString());
            
            recordQuery.setParameter("msg", msg);
            
            if (orgCode != null && !"".endsWith(orgCode)) {
                recordQuery.setParameter("orgCode", orgCode + "%");
            }
    
            recordQuery.setParameter("startDate", starttime);
            recordQuery.setParameter("endDate",  DateUtil.getStartDate(endtime, 1));
            
            int count = recordQuery.executeUpdate();
            return count;

    报错:

    javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement

    SQL Error: 1064, SQLState: 42000

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'set description='confirmed by app' where 1=1 and (orgz_code like '10021007%') an' at line 1

    sql执行都是成功的

    SELECT a.* from tip_s_DeviceAlarmOperateInfo a LEFT JOIN tip_s_systemdeviceinfo d on d.id = a.Device_id left JOIN s_organization o on o.id = d.organization_id where 1=1 and o.orgz_code like '10021007%'

    update tip_s_DeviceAlarmOperateInfo a LEFT JOIN tip_s_systemdeviceinfo d on d.id = a.Device_id left JOIN s_organization o on o.id = d.organization_id set a.description='aaa' where 1=1 and o.orgz_code like '10021007%'

    去掉关联表的字段匹配后,是可以执行的

            StringBuffer recordSql = new StringBuffer(200);
            
            recordSql.append(" update DeviceAlarmOperateInfo a set a.description = :msg where 1 = 1 ");
            
            recordSql.append(" and a.modifiedUser = null ");
    
            recordSql.append(" and a.currentstatus <> 0 ");
    
            recordSql.append(" and a.operatetime >= :startDate ");
    
            recordSql.append(" and a.operatetime < :endDate ");
    
            Query recordQuery = em.createQuery(recordSql.toString());
            
            recordQuery.setParameter("msg", msg);
    
            recordQuery.setParameter("startDate", starttime);
            recordQuery.setParameter("endDate",  DateUtil.getStartDate(endtime, 1));
            
            int count = recordQuery.executeUpdate();
            return count;
  • 相关阅读:
    金融风控100道面试题:传统银行开发转行互金top3公司并年薪40多万
    想学好矩阵?首先你要知道矩阵的历史!​
    什么是卷积?
    CNN的卷积核是单层的还是多层的?
    AI换脸之后“AI换声”来了!,一小时诈骗173万!
    介绍两个面试神器
    Github最火!程序员必须知道22大定律和法则
    SQL常用运算符
    SQL利用通配符进行模式查询
    隐藏DataList里面的某一行数据
  • 原文地址:https://www.cnblogs.com/LcxSummer/p/13158535.html
Copyright © 2011-2022 走看看