java.sql.SQLSyntaxErrorException: ORA-00904: " ": invalid identifier错误

原因是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+" '

 

 

 

posted on 2012-11-29 15:35  juan1206  阅读(2382)  评论(0编辑  收藏  举报

导航