原因是sql或hql拼接有问题

错误代码:

 

public GemStorageHistory gemid(String code){
List<GemStorageHistory> list=this.daoPersistence.query("from GemStorageHistory gh where gh.gemStorageCode="+code);
return list.size()>0?list.get(0):null;
}

错误原因:拼接字符串有误:gh.gemStorageCode="+code

正确方法:

public GemStorageHistory gemid(String code){
List<GemStorageHistory> list=this.daoPersistence.query("from GemStorageHistory gh where gh.gemStorageCode='"+code+"'");
return list.size()>0?list.get(0):null;
}

正确拼接:应给字符串在加个单引号 。如: gh.gemStorageCode=' "+code+" '

 

 

 

相关文章:

  • 2022-03-03
  • 2022-12-23
  • 2021-04-26
  • 2022-12-23
  • 2022-02-08
  • 2021-11-06
  • 2021-06-20
猜你喜欢
  • 2021-08-06
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案