我有一個SQLite數據庫,其中我正嘗試使用ID讀取數據庫中的最後8行。基於SQLite中的ID查詢最後N行
我在查詢時遇到問題。似乎無法做到。
public String lastEightRows(){
String[] columns = new String[] {KEY_ROWID, KEY_COLORS};
String result30 = " ";
String where = "ORDER BY" + KEY_ROWID + "DESC LIMIT" + 8;
//This is where I am not able to get the query right
Cursor c = ourDatabase.query(DATABASE_TABLE, columns, where, null, null, null, null);
int iRow = c.getColumnIndex(KEY_ROWID);
int iColors = c.getColumnIndex(KEY_COLORS);
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
result30 = result30 + c.getString(iRow) + " " + c.getString(iColors) + " " + "\n";
}
return result30;
}
我得到這個錯誤消息
03-26 22:58:27.420: E/AndroidRuntime(1368): android.database.sqlite.SQLiteException: near "DESC": syntax error (code 1): , while compiling: SELECT _id, persons_colors FROM personsTable WHERE _id DESC LIMIT 8
什麼是我們的數據庫?它的contentresolver或sqliteDatabase? – Amadas
sqlitedatabase的名稱 – artist
你的錯誤是什麼?你調試你的應用程序? – Sree