新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
對Hibernatesum函數(shù)的使用之分析
在使用Hibernate的sum函數(shù)進行數(shù)據(jù)的統(tǒng)計時,出現(xiàn)一個錯誤代碼:

創(chuàng)新互聯(lián)專注于網(wǎng)站建設|網(wǎng)站維護|優(yōu)化|托管以及網(wǎng)絡推廣,積累了大量的網(wǎng)站設計與制作經驗,為許多企業(yè)提供了網(wǎng)站定制設計服務,案例作品覆蓋成都廣告推廣等行業(yè)。能根據(jù)企業(yè)所處的行業(yè)與銷售的產品,結合品牌形象的塑造,量身定制品質網(wǎng)站。
Java代碼
String sql = "select SUM(nf.fee) from CFee as nf where nf.adminAccount='testaccount' "; String sql = "select SUM(nf.fee) from CFee as nf where nf.adminAccount='testaccount' "; |
這樣使用報null錯誤.
List的size明明等于1,但li.get(0)還是為空.(數(shù)據(jù)庫中查詢的賬號sum本來就為null??可能是.)
解決方法:
Java代碼
String sql = "select SUM(nf.fee) from CFee as nf where nf.adminAccount='testaccount' "; String sql = "select SUM(nf.fee) from CFee as nf where nf.adminAccount='testaccount' "; |
解決方法很簡單,就是增加一個判斷就可以了,如果li.get(0)為空,則返回0,不為空,返回值. 這樣就可以解決Hibernate sum函數(shù)使用出錯的問題。
【編輯推薦】
- 選擇EJB3.0,不再需要Spring+Hibernate
- Hibernate一對多關系的處理
- Struts與Hibernate的***結合方案
- 淺談Struts分頁中的Hibernate如何實現(xiàn)
文章標題:對Hibernatesum函數(shù)的使用之分析
鏈接分享:http://m.fisionsoft.com.cn/article/djghsjc.html


咨詢
建站咨詢
