我收到此错误
android.database.sqlite.SQLiteException: near "SELECT": syntax error: , while compiling: SELECT _id, c_type, s_name, s_numb, user_name, password FROM accounts WHERE SELECT * FROM TableName LIMIT 1 OFFSET 1
以下是创建问题的代码。我的目的是从表中获取ith
记录的ROWID,然后使用该ROWID从表中删除一个条目。
public void deleteEntry(long i) {
String[] columns = new String[]{KEY_ROWID, KEY_CTYPE, KEY_SNAME, KEY_SNUMB, KEY_USRN, KEY_PASS};
Cursor cursor = ourDatabase.query(DATABASE_TABLE,columns,"SELECT * FROM " +DATABASE_TABLE+" LIMIT 1 OFFSET "+i, null, null, null, null, null);
if (cursor != null && cursor.moveToFirst())
{
cursor.moveToFirst();
long rowIds = cursor.getLong(0);
ourDatabase.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowIds, null);
}
// ourDatabase.delete(DATABASE_TABLE, KEY_SNUMB + "=" + siteNum, null);
//return ourDatabase.insert(DATABASE_TABLE,null,cv);
}
答案 0 :(得分:1)
我通过改变方法实现了结果,但是当我学习android并且是初学者时,我想知道如何修复我在问题中提到的代码
String[] columns = new String[]{KEY_ROWID, KEY_CTYPE, KEY_SNAME, KEY_SNUMB, KEY_USRN, KEY_PASS};
Cursor cursor = ourDatabase.query(DATABASE_TABLE, null, null, null, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
cursor.moveToFirst();
for(int x=0;x<i;x++)
{
cursor.moveToNext();
}
long rowIds = cursor.getLong(0);
ourDatabase.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowIds, null);
}