Get all rows from SQLite

前端 未结 7 1843
执笔经年
执笔经年 2020-12-14 14:14

I have been trying to get all rows from the SQLite database. But I got only last row from the following codes.

FileChooser class:

p         


        
7条回答
  •  心在旅途
    2020-12-14 14:50

    public List getAllData(String email)
    {
    
        db = this.getReadableDatabase();
        String[] projection={email};
    
        List list=new ArrayList<>();
    
        Cursor cursor = db.query(TABLE_USER, //Table to query
                null,    //columns to return
                "user_email=?",        //columns for the WHERE clause
                projection,        //The values for the WHERE clause
                null,       //group the rows
                null,       //filter by row groups
                null);
        //  cursor.moveToFirst();
    
        if (cursor.moveToFirst()) {
            do {
    
                list.add(cursor.getString(cursor.getColumnIndex("user_id")));
                list.add(cursor.getString(cursor.getColumnIndex("user_name")));
                list.add(cursor.getString(cursor.getColumnIndex("user_email")));
                list.add(cursor.getString(cursor.getColumnIndex("user_password")));
                // cursor.moveToNext();
    
            } while (cursor.moveToNext());
        }
        return list;
    }
    

提交回复
热议问题