您的位置:首页 > 其它

Position beyond number of declared ordinal parameters. Remember that ordinal parameters are 1-based!

2017-03-09 13:17 417 查看
这种问题是你设置参数时下表超过了你的sql的问号(占位符)的下表,

public void excuteNamedQuery(String queryName, Object... args) {
//得到session
Session session = this.getSessionFactory().getCurrentSession();
Query query = session.getNamedQuery(queryName);
if(args != null && args.length > 0) {
int i = 0;
for (Object o:args) {
query.setParameter(i++,o);
/*if (i > args.length)
break;*/
}
}
query.executeUpdate();
}

我开始写成 int i = 1; 因为Hibernate的设置参数的索引从0开始,如果设置从1开始,到第二个就越界了,因为我的HQL语句就两个占位符

update User set password=? where id=?


值得注意的是:jdbc的这只参数却是从1开始的,这个很容易混淆
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: