preparedStatement = connection.prepareStatement("select fname,lname, "
+ "sportman_code,start,finish,salary,amount,number,pnumber "
+ "from sportman,customer "
+ "where customer.customer_code = "
+ "sportman.customer_code order by ? limit ?,?");
preparedStatement.setString(1, "fname");
preparedStatement.setInt(2, 0);
preparedStatement.setInt(3, 9);
resultSet = preparedStatement.executeQuery();order by不起作用。为什么?
当我用fname代替的时候?它可以正常工作。
"sportman.customer_code order by fname limit ?,?");我该怎么做呢?
发布于 2011-04-23 05:16:47
您不能绑定诸如表名或列名之类的标识符,只能绑定要插入、比较等的值
发布于 2011-04-23 05:20:18
您的ORDER BY可以工作,但并不是您期望的那样。当您使用
preparedStatement.setString(1, "fname");它会像这样下订单
ORDER BY 'fname'也不是你想的那样
ORDER BY fname然后,问题中的代码将类似于按字母顺序对M&M包进行排序
发布于 2011-04-23 05:21:58
绑定适用于查询中的文字,而不适用于关键字或标识符。如果希望排序字段是动态的,则需要使用另一种方法对其进行清理。
https://stackoverflow.com/questions/5760125
复制相似问题