增加數據
Users users = new Users()
users
setPwd=
admin
;
users
setName=
admin
;
Session session = HibernateSessionFactory
getSession()
session
beginTransaction()
session
save(users)
session
getTransaction()
commit()
修改數據
session
update(users)
刪除數據
session
delete(users)
注意
和
中使用的users中要包含主鍵的值
查詢數據
String HQLString =
*****
;
Session session = HibernateSessionFactory
getSession()
Query query = session
createQuery(HQLString)
java
util
List list = query
list()
for(Object o : list){
Users u = (Users)o;
System
out
println(u
getPwd+
+u
getName)
}
注
中的HQLString 為以下值時
form User
//查詢出User中所有的信息
form User u where u
name =
admin
//這個是條件查詢
也可以在 u 的前面加 as
delete from Users u where u
pwd =
admin
//按條件刪除數據
update Users u set u
pwd =
admin
where u
name =
aaa
//按條件更新
From:http://tw.wingwit.com/Article/program/Java/ky/201311/28354.html