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

原因是sql或hql拼接有问题

错误代码:

 

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

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

 

 

 

转载于:https://www.cnblogs.com/leess/archive/2012/11/29/2794758.html

你可能感兴趣的:(java.sql.SQLSyntaxErrorException: ORA-00904: " ": invalid identifier错误)