0
我有這個函數應該從數據庫中通過ID返回對象。儘管請求的ID有數據,但不會返回任何數據。有人能幫我解決這個問題嗎?SQLITE不返回請求的數據
代碼:
public ChildRecord getChild(int id) {
ChildRecord child = null;
Log.v("--", "success13s ");
Cursor c = database.rawQuery("SELECT * FROM child " + "WHERE childID="
+ id, null);
Log.v("--", "success1 2");
if (c != null)
if (c.moveToFirst()) {
do {
int childid = c.getInt(0);
String parent1 = c.getString(1);
String parent2 = c.getString(2);
String name = c.getString(3);
String dob = c.getString(4);
int gender = c.getInt(5);
String height = c.getString(6);
String weight = c.getString(7);
String etnicity = c.getString(8);
int type = c.getInt(9);
child = new ChildRecord(childid, name, dob, gender, height,
weight, etnicity, type, parent1, parent2);
} while (c.moveToNext());
}
Log.v("--", "success1 ");
return child;
}
的問題是在該行
Cursor c = database.rawQuery("SELECT * FROM child " + "WHERE childID="
+ id, null);
'id'在那一行有什麼值?這個值是否存在於表中? – Simon
是的,但我試圖找出有其他錯誤.. –
數據庫中的'childID'的類型是什麼?隱式類型轉換(例如,從'blob'類型到'int')可能會導致意想不到的結果。 – Trinimon