java.lang.IllegalArgumentException:参数不作为命名参数存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10748234/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.IllegalArgumentException: Parameter does not exist as a named parameter in
提问by Mango
public List<Data> List(String name, String id, int lowerBound, int upperBound) throws WiMatchException {
try {
Session session = getHibernateTemplate().getSessionFactory().openSession();
SQLQuery query = session.createSQLQuery("select * from data inner join route on (data.id=route.data_id and data.status=:status and data.is_active='Y' and route.owner_id= :ownerId) LIMIT lowerBound,upperBound ");
query.addEntity(UserData.class);
query.setString("status", status);
query.setString("ownerId", ownerId);
query.setInteger("lowerBound", lowerBound);
query.setInteger("upperBound", upperBound);
List<UserData> resList = query.list();
logger.debug("size of List() =" + resList.size());
session.close();
return resList;
} catch (Exception e) {
...
}
}
When executing the above method I'm getting following exception
执行上述方法时,我收到以下异常
java.lang.IllegalArgumentException: Parameter lowerBound does not exist as a named parameter in [select * from data inner join route on (data.id=route.data_id and data.status=:status and data.is_active='Y' and route.owner_id= :ownerId) LIMIT lowerBound,upperBound ]
Need suggestions to resolve this
需要建议来解决这个问题
回答by dasblinkenlight
You are missing parameter designators (colons) in front of lowerBound
and upperBound
.
您在lowerBound
和前面缺少参数指示符(冒号)upperBound
。
SQLQuery query = session.createSQLQuery(
"select * from data "+
"inner join route on (data.id=route.data_id and data.status=:status and data.is_active='Y' and route.owner_id= :ownerId)"+
"LIMIT :lowerBound,:upperBound "
);
Without these designators JDBC does not know that these are parameters, confusing them for column names.
没有这些指示符,JDBC 不知道这些是参数,因此会将它们与列名混淆。