DataBaseAdapter方法:Android:我的查詢出了什麼問題?
public long insertRecordCategory(String name, String device)
{
ContentValues cv = new ContentValues();
cv.put(NAME, name);
cv.put(DEVICE, device);
if(!updateRecord(cv, device))
return db.insert(TABLE, null, cv);
else return 0;
}
private boolean updateRecord(ContentValues values, String device) {
return db.update(TABLE, values, DEVICE + "=" + device, null) > 0;
}
public String isDeviceRegistered(String device) {
String [] coloane = {NAME, DEVICE};
Cursor c = db.query(true, TABLE, coloane, DEVICE + "=" + device, null, null, null, null, null);
if(c == null)
return null;
c.moveToFirst();
return c.getString(c.getColumnIndex(NAME));
}
當我試圖調用:isDeviceRegistered它說:
05-25 16:44:47.170: E/AndroidRuntime(14504): android.database.sqlite.SQLiteException: near ":02": syntax error (code 1): , while compiling: SELECT DISTINCT _name, _device FROM FriendsTable WHERE _device=22:02:af:db:24:9a
當調用更新它說:
05-25 17:36:55.190: E/AndroidRuntime(469): android.database.sqlite.SQLiteException: near ":02": syntax error (code 1): , while compiling: UPDATE FriendsTable SET device=?,name=? WHERE device=22:02:af:db:24:9a
而這種更新方法與其工作的另一個項目是相同的。
感謝,怎麼樣更新方法? –
這同樣適用於它。 – laalto