當前位置:首頁 » 編程語言 » 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; }

熱點內容
鳥存儲空氣 發布:2025-05-18 00:20:24 瀏覽:200
linux刻錄iso 發布:2025-05-18 00:16:15 瀏覽:661
php動態參數 發布:2025-05-18 00:12:05 瀏覽:425
安卓應用上傳 發布:2025-05-18 00:11:57 瀏覽:802
數對的演算法 發布:2025-05-18 00:11:02 瀏覽:381
linuxwhile 發布:2025-05-18 00:10:08 瀏覽:143
xpftp外網 發布:2025-05-17 23:58:11 瀏覽:385
如何評價一個伺服器的性能 發布:2025-05-17 23:40:53 瀏覽:270
淘寶客適合什麼伺服器 發布:2025-05-17 23:39:26 瀏覽:613
python循環文件 發布:2025-05-17 23:39:22 瀏覽:829