當前位置:首頁 » 編程語言 » javaqueryquery

javaqueryquery

發布時間: 2023-06-03 11:18:46

java中查詢最大id的方法如何定義

方法如下:
@Override

@Transactional(propagation=Propagation.REQUIRED)

public long findBusinessIdMAX() throws WuliuguanliException {

Session session=null;

session=factory.getCurrentSession();

String hql="select max(b.id) from Business b";

Query query=session.createQuery(hql);

Long count=(Long) query.uniqueResult();

return count;

}

Ⅱ java中資料庫有關的createQuery方法怎麼用

createQuery不是資料庫的方法,這是hibernate的sql操作方法。
具體作用,是對查詢語句的執行·,像「select * from tb_a...」這樣的sql語句。
可以傳參,通用方法有兩種:

String hql = "from InventoryTask it where it.orgId=:orgId";
Session session = getSession();
Query query=session.createQuery(hql);
query.setString("orgId",orgId);
List list = query.list();
if(list!=null&&list.size()!=0){
return (InventoryTask)list.get(0);
}else{
return null;
}String hql = "from InventoryTask it where it.orgId=?,it.orgName"; Session session = getSession(); Query query=session.createQuery(hql); query.setString("0",orgId); query.setString(1,orgName) List list = query.list(); if(list!=null&&list.size()!=0){ return (InventoryTask)list.get(0); }else{ return null; }

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:710
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:972
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:681
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:834
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:741
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1081
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:312
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:192
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:880
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:837