//查詢單個欄位
String hql = " select name from Users";
Query query = session.createQuery(hql);
List
for(String str : list){
System.out.println(str);
}
輸出結果為:
name1
name2
name3
//查詢其中幾個欄位
String hql = " select name,passwd from Users";
//預設查詢出來的list裡存放的是一個Object陣列
for(Object[] object : list){
String name = (String)object[0];
String passwd = (String)object[1];
System.out.println(name + " : " + passwd);
name1 : password1
name2 : password2
name3 : password3
//查詢單個欄位
String hql = " select name from Users";
Query query = session.createQuery(hql);
List
for(String str : list){
System.out.println(str);
}
輸出結果為:
name1
name2
name3
//查詢其中幾個欄位
String hql = " select name,passwd from Users";
Query query = session.createQuery(hql);
//預設查詢出來的list裡存放的是一個Object陣列
List
for(Object[] object : list){
String name = (String)object[0];
String passwd = (String)object[1];
System.out.println(name + " : " + passwd);
}
輸出結果為:
name1 : password1
name2 : password2
name3 : password3