
Here I created a model class and used this model while fetching the data from SQLITE database in android.

To read the data from any table, create a model class which will hold all the data. For Android, SQLite is baked into the Android runtime, so every Android application can create its own SQLite databases. Android SQLite combines a clean SQL interface with a very small memory footprint and decent speed. Reading Android SQLITE Data From Database Android SQLite is a very lightweight database which comes with Android OS. Here, you have to override the onCreate () and onUpdate () methods. SQLiteDatabase db this.getWritableDatabase () ContentValues values new ContentValues () values.put (COLNAME, VALUE) values.put (COLNAME, VALUE) // Inserting Row db. First of all, you should create a Java class that extends SQLiteOpenHelper. From a remote shell to your device or from your host machine, use the sqlite3 command-line program to manage SQLite databases created by Android applications. You can use ContentValues to insert into your database. Public class SqliteHelper extends SQLiteOpenHelper ) All the DBs you create inside your app will be accessible from all the classes of your apps (NOT outside your app). Step 4: Creating a new Java class for performing SQLite operations.

When you extends it to the SQLiteOpenHelper, You will get a red sign on the left side, Click on that and get the constructor and override the two methods. The proper design in this case is to create a table categories like: CREATE TABLE categories(id INTEGER PRIMARY KEY, category TEXT) Īnd store all the categories there: INSERT INTO categories(category) VALUES What if you want to add a new category? You would have to redefine the enum values in the table's definition and this is not possible in SQLite unless you recreate the table (as you can find here). There is no ENUM data type in SQLite, but even if there was one it would not be the best way to define this column.
