PreparedStatement不返回有序的ResultSet [英] PreparedStatement not returning ordered ResultSet

查看:158
本文介绍了PreparedStatement不返回有序的ResultSet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一些问题,我敢肯定这是愚蠢的.

I am having some problems and I'm sure it's something stupid.

所以我有一个类似的查询

So I have a query like

SELECT name, id, xyz FROM table ORDER BY ?

然后再设置?

ps.setString(1, "xyz");

我正在控制台中输出查询和xyz的值.当我遍历从PreparedStatement返回的ResultSet时,值的顺序不正确.它们按照返回的顺序排列,就好像我已经取消了ORDER BY子句一样.当我将查询和值复制/粘贴到TOAD时,它将运行并正确返回.

I am outputting the query and the value of xyz in the console. When I loop through the ResultSet returned from the PreparedStatement the values are not in the correct order. They are in the returned order as if I had left the ORDER BY clause off. When I copy/paste the query and the value into TOAD it runs and comes back correctly.

对为什么ResultSet不能按正确顺序返回的任何想法吗?

Any ideas to why the ResultSet is not coming back in the correct order?

推荐答案

数据库会将查询视为

SELECT name, id, xyz FROM table ORDER BY 'xyz'

也就是说,按常量表达式排序(在这种情况下为字符串"xyz").任何订单都可以满足要求.

That is to say, order by a constant expression (the string 'xyz' in this case). Any order will satisfy that.

这篇关于PreparedStatement不返回有序的ResultSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆