开发者

getting data from database table using cursor in android

I have one employee table which has column values

("store_loc_id","name","password","address_id","role_id",
"retailer_id").

I want to get the name and password from this ta开发者_开发百科ble using cursor. how can i do??


Haven't check this code, but the idiom should be understandable.

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());
            }
        } 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜