我有这个函数应该通过ID从数据库返回对象。尽管按请求的ID存在数据,但不返回任何数据。有人可以帮我解决这个问题。
代码:
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);
答案 0 :(得分:0)
我想首先明确这一点,如果你的“child”表中包含整数的“childID”列,并且你传入的id都有数据。查询字符串没有问题。
然后你应该检查:
您是指“正确的”数据库
尝试在SQLite数据库管理器中执行此查询,看看是否会产生结果。
请尝试告诉我你的结果。