这种问题是你设置参数时下表超过了你的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开始的,这个很容易混淆
转载请注明原文地址: https://ju.6miu.com/read-10766.html