Extract the results into a List<YourResultType> and use Collections.sort(). If you only ever need to sort in one "natural" order, then implement Comparable<T> in the result type itself... otherwise implement Comparator<T> once per sort order, and pass an instance of the relevant comparator to Collections.sort().
你ORDER BY在数据库中.
你应该重新评估为什么你不能这样做.如果有人问"如何用锤子插入螺丝?我不能使用螺丝刀",不要说服他们说螺丝刀在第一种情况下是正确的解决方案是不负责任的.
如果你真的,真的无法原生地订购结果集,那你就不走运了.它只是来自数据库的一个流,所以你必须把它全部读成一个临时的List,对那个集合进行排序,然后从那里开始.对于较小的结果集,这可能不是一个问题,但对于较大的结果集,这可能会对效率造成很大影响.
| 归档时间: |
|
| 查看次数: |
15975 次 |
| 最近记录: |