2

I'm just interesting: can I use something else for retrieving data from the database instead of using Cursor like this:

Cursor fetch_ = database_.rawQuery("SELECT " + USER_ID + " FROM " + TABLE_NAME, null);
if (fetch_.moveToFirst()) {
    do {
        String data_ = fetch_.getString(fetch_.getColumnIndex("userId"));
    } while (fetch_.moveToNext());
}
fetch_.close();

So are there some other ways? May be I can fetch data directly in Java data structures like HashMap<> or something else?

MainstreamDeveloper00
  • 8,436
  • 15
  • 56
  • 102

1 Answers1

4

Yes, you can use some ORM library, see: Any good ORM tools for Android development?

My personal favorite is ActiveAndroid library (https://www.activeandroid.com/)

See the documentation: https://github.com/pardom/ActiveAndroid/wiki


For example

@Table(name = "Items")
public class Item extends Model {
    @Column(name = "Name")
    public String name;

    @Column(name = "Category")
    public Category category;
}

Fetching all should be like

List<Item> items = new Select().from(Item.class).execute();
Community
  • 1
  • 1
Marek Sebera
  • 39,650
  • 37
  • 158
  • 244