日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
對(duì)Hibernatesum函數(shù)的使用之分析

在使用Hibernate的sum函數(shù)進(jìn)行數(shù)據(jù)的統(tǒng)計(jì)時(shí),出現(xiàn)一個(gè)錯(cuò)誤代碼:

創(chuàng)新互聯(lián)專注于網(wǎng)站建設(shè)|網(wǎng)站維護(hù)|優(yōu)化|托管以及網(wǎng)絡(luò)推廣,積累了大量的網(wǎng)站設(shè)計(jì)與制作經(jīng)驗(yàn),為許多企業(yè)提供了網(wǎng)站定制設(shè)計(jì)服務(wù),案例作品覆蓋成都廣告推廣等行業(yè)。能根據(jù)企業(yè)所處的行業(yè)與銷售的產(chǎn)品,結(jié)合品牌形象的塑造,量身定制品質(zhì)網(wǎng)站。

Java代碼

String sql = "select SUM(nf.fee) from CFee as nf where   nf.adminAccount='testaccount' ";
public long getListSqlCountsLong(String sql) {
beginTransaction();
List li = getSession().createQuery(sql).list();
if (li == null || li.isEmpty()) {
return 0;
} else {return ((Integer) li.get(0)).longValue();
}
}
String sql = "select SUM(nf.fee) from CFee as nf where   nf.adminAccount='testaccount' ";
public long getListSqlCountsLong(String sql) {
beginTransaction();
List li = getSession().createQuery(sql).list();
if (li == null || li.isEmpty()) {
return 0;
} else {return ((Integer) li.get(0)).longValue();
}
}

這樣使用報(bào)null錯(cuò)誤.
List的size明明等于1,但li.get(0)還是為空.(數(shù)據(jù)庫(kù)中查詢的賬號(hào)sum本來(lái)就為null??可能是.)
解決方法:

Java代碼

String sql = "select SUM(nf.fee) from CFee as nf where   nf.adminAccount='testaccount' ";
public long getListSqlCountsLong(String sql) {
beginTransaction();
List li = getSession().createQuery(sql).list();
if (li == null || li.isEmpty()) {
return 0;
} else {
if (li.get(0) == null) {
return 0;
}
return ((Integer) li.get(0)).longValue();
}
}
String sql = "select SUM(nf.fee) from CFee as nf where   nf.adminAccount='testaccount' ";
public long getListSqlCountsLong(String sql) {
beginTransaction();
List li = getSession().createQuery(sql).list();
if (li == null || li.isEmpty()) {
return 0;
} else {
if (li.get(0) == null) {
return 0;
}
return ((Integer) li.get(0)).longValue();
}
}

解決方法很簡(jiǎn)單,就是增加一個(gè)判斷就可以了,如果li.get(0)為空,則返回0,不為空,返回值. 這樣就可以解決Hibernate sum函數(shù)使用出錯(cuò)的問(wèn)題。

【編輯推薦】

  1. 選擇EJB3.0,不再需要Spring+Hibernate
  2. Hibernate一對(duì)多關(guān)系的處理
  3. Struts與Hibernate的***結(jié)合方案
  4. 淺談Struts分頁(yè)中的Hibernate如何實(shí)現(xiàn)

分享名稱:對(duì)Hibernatesum函數(shù)的使用之分析
文章源于:http://www.5511xx.com/article/djghsjc.html