我正在使用此代码进行更新,但是却遇到类似查询必须以select or from : update开头的错误,因此请帮助我:

public static void changeOccup(String email,String occup){
 try{  Session sess=UtilClass.createSession();
  Transaction tx=sess.beginTransaction();Query que=sess.createQuery("update Userrecord set occupation=occup where emailId=email");
  que.setParameter("occup", occup);
  que.setParameter("email", email);
  int result=que.executeUpdate();
  JOptionPane.showMessageDialog(null,"occup changed"+result);
    tx.commit();
 }

最佳答案

使用SQLQuerycreateSQLQuery代替QuerycreateQuery。如果您使用的是QuerycreateQuery,则必须使用Hibernate的语法。如果需要常规的SQL语法,请使用SQLQuery

关于java - 查询必须以select或from开头:update,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22795359/

10-11 02:51