java报错beyond number of declared ordinal parameters. Remember
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/11 14:18:08
java报错beyond number of declared ordinal parameters. Remember that ordinal parameters are 1-based!
问题就出在这里
public Result getAdminRecordList(VOFilter filter) {
Result r = new Result();
Page page = filter.getPage();
EntityManager em = getEntityManager();
try {
Query query = em
.createQuery(" select count(o) from log_login as o");
Long count = (Long) query.getSingleResult();
page.setCount(count);
String jsql = " from log_login as o";
if (!StringUtil.isEmpty(filter.getKeyWord())) {
jsql += " where o.name like ? ";
}
if (filter.getOrders().size() > 0) {
jsql += " order by ";
for (Order order : filter.getOrders()) {
if ("id".equals(order.getField())) {
jsql += "o.id";
} else if ("logtime".equals(order.getField())) {
jsql += "o.logtime";
} else if ("name".equals(order.getField())) {
jsql += "o.name";
} else if ("result".equals(order.getField())) {
jsql += "o.result";
} else if ("ip".equals(order.getField())) {
jsql += "o.ip";
} else {
jsql +="o.ip";
}
if (order.getDirection() == Order.DESC) {
jsql += " desc,";
} else {
jsql += " asc ,";
}
}
jsql = jsql.substring(0, jsql.length() - 1);
}
query = em.createQuery(jsql);
query.setFirstResult(page.getStartRowNum());
query.setMaxResults(page.getPageSize());
if (!StringUtil.isEmpty(filter.getKeyWord())) {
query.setParameter(1, "%" + filter.getKeyWord() + "%");
query.setParameter(2, "%" + filter.getKeyWord() + "%");
}
r.setData(query.getResultList());
r.setPage(page);
return r;
} finally {
if (em != null) {
em.close();
}
}
}
问题就出在这里
public Result getAdminRecordList(VOFilter filter) {
Result r = new Result();
Page page = filter.getPage();
EntityManager em = getEntityManager();
try {
Query query = em
.createQuery(" select count(o) from log_login as o");
Long count = (Long) query.getSingleResult();
page.setCount(count);
String jsql = " from log_login as o";
if (!StringUtil.isEmpty(filter.getKeyWord())) {
jsql += " where o.name like ? ";
}
if (filter.getOrders().size() > 0) {
jsql += " order by ";
for (Order order : filter.getOrders()) {
if ("id".equals(order.getField())) {
jsql += "o.id";
} else if ("logtime".equals(order.getField())) {
jsql += "o.logtime";
} else if ("name".equals(order.getField())) {
jsql += "o.name";
} else if ("result".equals(order.getField())) {
jsql += "o.result";
} else if ("ip".equals(order.getField())) {
jsql += "o.ip";
} else {
jsql +="o.ip";
}
if (order.getDirection() == Order.DESC) {
jsql += " desc,";
} else {
jsql += " asc ,";
}
}
jsql = jsql.substring(0, jsql.length() - 1);
}
query = em.createQuery(jsql);
query.setFirstResult(page.getStartRowNum());
query.setMaxResults(page.getPageSize());
if (!StringUtil.isEmpty(filter.getKeyWord())) {
query.setParameter(1, "%" + filter.getKeyWord() + "%");
query.setParameter(2, "%" + filter.getKeyWord() + "%");
}
r.setData(query.getResultList());
r.setPage(page);
return r;
} finally {
if (em != null) {
em.close();
}
}
}
hql多了参数了,你就一个占位符 - ,却使用了query.setParameter(2,"%" + filter.getKeyWord() + "%");
再问: 谢谢。。昨天就解决了。。。忘了来看。。。删掉query.setParameter(2, "%" + filter.getKeyWord() + "%"); 就可以了
再问: 谢谢。。昨天就解决了。。。忘了来看。。。删掉query.setParameter(2, "%" + filter.getKeyWord() + "%"); 就可以了
java报错beyond number of declared ordinal parameters. Remember
java.sql.SQLException:Wrong number of parameters是什么意思,就是修改内容
Parameter index out of range (1 > number of parameters,which
Parameter index out of range (1 > number of parameters, whic
Parameter index out of range (4 > number of parameters,which
程序老是报错 `a' was not declared in this scope
java中定义Map 报错
java 中import java.sql.Connection 报错:The import java.sql.Conn
matlab报错:In an assignment A(i,j) = B,the number of columns i
英语翻译Never increase,beyond what is necessary,the number of en
java 连接oracle报错java.sql.SQLException: Listener refused the c
beyond the shadow of