我有一个employee table
,其中包含列值
("store_loc_id","name","password","address_id","role_id",
"retailer_id").
我想使用游标从此表中获取name
和password
。我怎么办?
答案 0 :(得分:1)
没有检查这段代码,但这个成语应该是可以理解的。
Cursor cursor = db.query(...);
if(cursor !=null && cursor.moveToFirst()) {
do {
String name = cursor.getString(cursor.getColumnIndex("name"));
} while (cursor.moveToNext());
}
答案 1 :(得分:0)
public Cursor getEmployee() {
try {
return db.query(employee, new String[] { "name", "password" },
null, null, null, null, null);
} catch (SQLException e) {
Log.e("Exception on query", e.toString());
return null;
}
}
Cursor c = db.getEmployee();
if (c == null) {
// do nothing
} else {
if (c.getCount() > 0) {
if (c.moveToFirst()) {
do {
String Name = c.getString(0);
String Password = c.getString(1);
} while (c.moveToNext());
}
}
}