我希望比较数据库中的用户名和密码(如果存在),如果不是成功,如果不是抛出错误我使用 SQLiteOpenHelper 来完成任务 我现在可以从数据库中获取一个字段如何检索多个字段
public UserInfo get_user_by_id(String id) {
SQLiteDatabase db = this.getReadableDatabase();
UserInfo userInfo = null;
Cursor cursor = db.query(TABLE_NAME, new String[]{COLUMN_APP_ID}, COLUMN_APP_ID + "=?", new String[]{id + ""}, null, null, null);
while (cursor.moveToNext()) {
//userInfo.setAppId(cursor.getString(cursor.getColumnIndex(COLUMN_APP_ID)));
userInfo = new UserInfo(cursor.getString(cursor.getColumnIndex(COLUMN_APP_ID)));
}
请提前帮助我
答案 0 :(得分:2)
从方法get_user_by_id()返回UserInfo列表。
public ArrayList<UserInfo> get_user_by_id(String id) {
ArrayList<UserInfo> listUserInfo = new ArrayList<UserInfo>();
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_NAME, new String[]{COLUMN_APP_ID}, COLUMN_APP_ID + "=?", new String[]{id + ""}, null, null, null);
if (cursor != null) {
while (cursor.moveToNext()) {
UserInfo userInfo = new UserInfo();
userInfo.setAppId(cursor.getString(cursor.getColumnIndex(COLUMN_APP_ID)));
// HERE YOU CAN MULTIPLE RECORD AND ADD TO LIST
listUserInfo.add(userInfo);
}
}
return listUserInfo;
}
答案 1 :(得分:1)
像这样使用SQLite Query ....
{{1}}