Get all rows from SQLite

前端 未结 7 1833
执笔经年
执笔经年 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:44

    Update queueAll() method as below:

    public Cursor queueAll() {
    
         String selectQuery = "SELECT * FROM " + MYDATABASE_TABLE;
         Cursor cursor = sqLiteDatabase.rawQuery(selectQuery, null);
    
         return cursor;
    }
    

    Update readFileFromSQLite() method as below:

    public ArrayList readFileFromSQLite() {
    
        fileName = new ArrayList();
    
        fileSQLiteAdapter = new FileSQLiteAdapter(FileChooser.this);
        fileSQLiteAdapter.openToRead();
    
        cursor = fileSQLiteAdapter.queueAll();
    
        if (cursor != null) {
            if (cursor.moveToFirst()) {
                do 
                {
                    String name = cursor.getString(cursor.getColumnIndex(FileSQLiteAdapter.KEY_CONTENT1));
                    fileName.add(name);
                } while (cursor.moveToNext());
            }
            cursor.close();
        }
    
        fileSQLiteAdapter.close();
    
        return fileName;
    }
    

提交回复
热议问题