gpt4 book ai didi

java - 请记住,序数参数是从 1 开始的!位置 : 1 in Mysql

转载 作者:行者123 更新时间:2023-11-29 19:01:49 26 4
gpt4 key购买 nike

我正在使用Hibernate和MySQL并面临查询sql的问题

hibernate 服务:

List<RenterDto> list = new ArrayList<RenterDto>(0);
try {
Query query = session.createSQLQuery(sqlString);
query.setParameter(0, name);
list = query.setResultTransformer(new AliasToBeanResultTransformer(RenterDto.class)).list();
} catch (HibernateException e) {
logger.error("error at RenterDaoImpl.searchByNamePersonalId: " + e.getMessage());
} finally {
session.close();
}
return list;

SQL:

SELECT 
R.ID,
R.NAME,
R.PERSONAL_ID,
R.PHONENUMBER,
R.EMAIL
FROM
RENTER R
WHERE
LOWER(R.NAME)
LIKE
CONCAT('%', '?')

调试时记录消息:

RenterDaoImpl - error at RenterDaoImpl.searchByNamePersonalId: Position beyond number of declared ordinal parameters. 
Remember that ordinal parameters are 1-based! Position: 1

如何解决这个问题,非常感谢!

最佳答案

按照错误消息的指示进行操作

query.setParameter(1, name);

关于java - 请记住,序数参数是从 1 开始的!位置 : 1 in Mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43816849/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com