-1

以下是导致问题的我的数据库方法:

 public Cursor fetchRecord(String pin,String category)throws SQLException
{

Cursor c=mDb.query(DATABASE_TABLE, new String[]
{KEY_ROWID,KEY_NAME,KEY_PHONE,KEY_CATEGORY,KEY_PINCODE},
KEY_PINCODE + "= ?" + "AND" + KEY_CATEGORY + "= ?",
new String[]{pin,category}, null, null, KEY_NAME);

    if (c!= null) {
        c.moveToFirst();
    }
    return c;
}

每当我输入并单击日志猫说的第一个活动中的“开始”按钮时,它就会强制关闭:

Caused by: android.database.sqlite.SQLiteException: near "ANDcategory": syntax error: , while compiling: SELECT _id, name, phone, category, pincode FROM details WHERE pincode= ?ANDcategory= ? ORDER BY name
4

2 回答 2

1

在您的 where 子句中,密码和类别之间必须有空格。

只需更换

"AND"

" AND "


public Cursor fetchRecord(String pin,String category)throws SQLException 
{ 

        Cursor c=mDb.query(DATABASE_TABLE, new String[]
 {KEY_ROWID,KEY_NAME,KEY_PHONE,KEY_CATEGORY,KEY_PINCODE},
KEY_PINCODE + "= ?" + 
" AND " + KEY_CATEGORY + "= ?",new String[]{pin,category}, null, null, KEY_NAME); 

    if (c!= null) { 
        c.moveToFirst(); 
    } 
    return c; 
}
于 2012-09-30T08:07:33.250 回答
0

阅读异常,它会告诉您您需要知道的一切:

syntax error: , while compiling: SELECT _id, name, phone, category, pincode FROM details WHERE pincode= ?ANDcategory= ? ORDER BY name
于 2012-09-30T07:14:36.187 回答