hibernate之Hql_update语句的用法:

版权声明: https://blog.csdn.net/wlk2064819994/article/details/79527822

 hibernate之Hql_update语句的用法:

介绍5种参数绑定进行数据库更新:

一、query.setParameter(属性名,真实值,类型);
String hql = “update User u set u.username = :newName where u.uid = :newId”;
Query query = getSession.createQuery(hql);
query.setParameter("newName",值,Hibernate.STRING);
query.executeUpdate();

二.query.setXXXX(属性值,真实值);
String hql="update User u set u.userName=:userName where u.userId=:userId";
query.setString("userName",userName);
query.setInteger("userId",userId);
query.executeUpdate();

三.query.setString(问号位置,真实值);
String hql="update User u set u.userName=? where u.userId=?";
Query query  = getSession.createQuery(hql); 
query.setString(0,userName);
query.setInteger(1,userId);
query.executeUpdate();

四.query.setProperties(对象);
String hql="update User u set u.userName=:userName where u.userId=:userId";
Query query  = getSession.createQuery(hql); 
User user = new User();
user.serUserName("张三");
user.setUserId(2);
query.setProperties(user);
query.executeUpdate();







阅读更多
换一批

没有更多推荐了,返回首页