spring jdbcTemplate queryForList 预编译 order by ?失效 带来的思考以及查阅资料 获取到的知识

在使用Spring JdbcTemplate的预编译查询时遇到order by无法正常工作的问题,导致结果集顺序混乱。研究发现,预编译的?占位符主要用于设置SQL字面量,而非改变数据库结构对象如表或列。这限制了驱动程序的预编译能力。当order by的列依赖于索引时,不同的索引状态会导致预编译语句的差异,影响PreparedStatement的效果。因此,?占位符不应用于列名或排序方向。
摘要由CSDN通过智能技术生成
String xx=" select *  from( select CLASSES,ID,TITLE ,to_char(pub_date,'yyyy-mm-dd')pub_date,URL,rownum rn from  urlmaptab where classes=? and flag='1' and auth_flag in('G') "+
				" and rownum<=? ) where rn>=? order by   ? desc";

list=getJdbcTemplate().queryForList(xx,new Object[]{classes,end,begin,order});

使用spring jdbcTemplate带预编译的查询方法查询时,发现结果是乱序的,也就是说oder by 失效了,问题出在哪里呢?

上网查阅资料:得到如下
The specification isn't explicit, but the context of the section on
PreparedStatements makes it clear that the ? placeholders are to be used
to set data, i.e. SQL literals, and not to allow you to vary database
schema objects like tables, columns, etc. This is natural and
understandable; the amount of pre-compilation a driver could do

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值