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+" '