ORDER BY 编号 1 标识的 SELECT 项包含一个变量,作为标识列位置的表达式的一部分。按照引用列名的表达式排序时,只允许使用变量

li634089522 2011-03-26 11:55:10
public List GetSelectStoreAll(String type,String name1)
{
List list = new ArrayList();
Connection conn=null;
PreparedStatement ps=null;
ResultSet rs=null;
conn=GetConn();
String sql="select id as 'ID' , name as '名字',number as '数量',price as '价格',type as '类型' from storge where type=? order by ? desc";
try {
ps=conn.prepareStatement(sql);
ps.setString(1, type);
ps.setString(2,name1);
rs=ps.executeQuery();
while(rs.next())
{
store s=new store(rs.getInt(1),rs.getString(2),rs.getInt(3),rs.getDouble(4),rs.getString(5));
list.add(s);
}

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return list;
}

运行后报由 ORDER BY 编号 1 标识的 SELECT 项包含一个变量,作为标识列位置的表达式的一部分。按照引用列名的表达式排序时,只允许使用变量。
请各位大虾帮忙解决一下
...全文
987 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
awusoft 2011-03-27
  • 打赏
  • 举报
回复
awusoft 2011-03-27
  • 打赏
  • 举报
回复
还没有试过order by使用参数的方式来完成,楼主就组装一下吧

String sql="select id as 'ID' , name as '名字',number as '数量',price as '价格',type as '类型' from storge where type=? order by "+name1+" desc";
24K純帥 2011-03-27
  • 打赏
  • 举报
回复
type=@type

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧