以下是导致问题的数据库方法:
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
答案 0 :(得分: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;
}
答案 1 :(得分:0)
阅读异常,它告诉你需要知道的一切:
syntax error: , while compiling: SELECT _id, name, phone, category, pincode FROM details WHERE pincode= ?ANDcategory= ? ORDER BY name