У меня есть один employee table
, который имеет значения столбцов
("store_loc_id","name","password","address_id","role_id",
"retailer_id").
Я хочу получить name
и password
из этой таблицы с помощью курсора. как я могу это сделать?
Не проверяйте этот код, но идиома должна быть понятной.
Cursor cursor = db.query(...);
if(cursor !=null && cursor.moveToFirst()) {
do {
String name = cursor.getString(cursor.getColumnIndex("name"));
} while (cursor.moveToNext());
}
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());
}
}
}
query