JDBCTemplate.queryForList 返回空列表
您能帮忙弄清楚为什么下面的Java代码返回
return this.getJdbcTemplate().queryForList(
"select cn from group g, group_relationship r, " +
"group_member m where g.name='administratorGroup' and g.group_id=r.group_id " +
"and r.member_id=m.member_id and m.cn like ?",
String.class,
new Object[] { cn + "%" });
我使用sqlplus,replace测试的空列表吗? with 'd%',查询返回以d开头的cn列表。
Could you please help to figure out why following Java code returns empty list
return this.getJdbcTemplate().queryForList(
"select cn from group g, group_relationship r, " +
"group_member m where g.name='administratorGroup' and g.group_id=r.group_id " +
"and r.member_id=m.member_id and m.cn like ?",
String.class,
new Object[] { cn + "%" });
I tested using sqlplus, replace ? with 'd%', The query returns a list of cn start with d.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
确保您没有为 cn == null 调用此函数,因为在这种情况下 cn + "%" 变为 "null%",这就是它可能返回 0 条记录的原因。
Make sure You're not calling this for cn == null, as in such case cn + "%" becomes "null%" and that's why it probably returns 0 records.
谢谢大家的帮助,问题解决了,我不知道JUnit测试正在使用内存数据库,试图将JUnit测试结果与测试数据库进行比较,在内存数据库中添加条目后,测试返回正确的结果
Thank you for everybody's help, The problem is solved, I was unaware JUnit test is using in-memory db, trying to compare the JUnit test result with test db, after add entries in in-memory db, test return correct result
除非变量
cn
是d
,否则最后是不正确的。is not correct at the end unless the variable
cn
isd
.