我需要按最新日期订购我的数据。
此SQL语句正常工作
final String selectSql = "select * from questionnaire where userprofileid=" + userProfileID ;
此SQL语句为** NOT working **
final String selectSql = "select * from questionnaire where userprofileid=" + userProfileID +"ORDER by datecreated desc";
错误消息:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:SQL语法中有错误;检查与MySQL服务器版本对应的手册,以便在第1行“by datecreated desc”附近使用正确的语法
答案 0 :(得分:4)
您需要在ORDER之前添加空格:
final String selectSql = "select * from questionnaire where userprofileid=" + userProfileID +" ORDER by datecreated desc";
答案 1 :(得分:1)
请在ORDER BY前留一个空格。 " ORDER BY datecreated desc"
答案 2 :(得分:1)
最终字符串应如下所示:
final String selectSql = "select *
from questionnaire
where userprofileid=" + userProfileID +
" ORDER by datecreated desc"; // add a space
// after the double
// quote