• 用HQL自己写了个update!!!


    原来代码:

    public void updateSj(String jsly, Integer zu,String sj) {
            if (!StringUtils.isBlank(jsly)&&null!=zu&&!StringUtils.isBlank(sj)) {
                Session session = sessionFactory.getCurrentSession();
    //            session.beginTransaction();
    //            SQLQuery query = session.createSQLQuery("UPDATE cq_num SET sj=:sj WHERE jsly=:jsly AND zu=:zu");
    //            query.setParameter("jsly", jsly);
    //            query.setParameter("zu", zu);
    //            query.setParameter("sj", sj);
    //            query.executeUpdate();
    //            session.getTransaction().commit();
                Query query = session.createQuery("UPDATE CqNum SET sj=? WHERE jsly=? AND zu=?");
                query.setString(0, sj);  
                query.setString(1, jsly);  
                query.setLong(2, zu);
                query.executeUpdate();
            }
        }

    其中:

    Session session = sessionFactory.getCurrentSession();
                session.beginTransaction();
                SQLQuery query = session.createSQLQuery("UPDATE cq_num SET sj=:sj WHERE jsly=:jsly AND zu=:zu");
                query.setParameter("jsly", jsly);
                query.setParameter("zu", zu);
                query.setParameter("sj", sj);
                query.executeUpdate();
                session.getTransaction().commit();

    也能更新,但是太慢啦!!!(session.beginTransaction();和session.getTransaction().commit();去掉)

    修改后代码:

    Query query = session.createQuery("UPDATE CqNum SET sj=? WHERE jsly=? AND zu=?");
                query.setString(0, sj);  
                query.setString(1, jsly);  
                query.setLong(2, zu);
                query.executeUpdate();

    OK!!!!!!!

  • 相关阅读:
    myeclipse 代码提示(alt+/)
    彻底解决mysql中文乱码
    Pycharm取消默认的右击运行unittest方法
    解决Ubuntu的root账号无法登录SSH问题-Permission denied, please try again.
    language support图标在哪里?怎么消失了?
    Ubuntu安装谷歌输入法或者搜狗
    最大流算法-ISAP
    WC2013-糖果公园
    bzoj4032-最短不公共子串
    bzoj1031-字符加密
  • 原文地址:https://www.cnblogs.com/zch-lxh1314/p/10294852.html
Copyright © 2020-2023  润新知