android tutorial - Basic usage in Android Sqlite | Developer android - android app development - android studio - android app developement



Basic usage

public class HelloDBHelper extends SQLiteOpenHelper {
    private static final int DATABASE_VERSION = 1;
    private static final int DATABASE_NAME = "hello";

    HelloDBHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE ...");
        ...
    }
}
click below button to copy code from our android learning website - android tutorial - team
  • This helper class is responsible for opening (and creating/updating, if needed) the database. Use it to get an SQLiteDatabase object to access the data:
SQLiteDatabase db = helper.getReadableDatabase();
Cursor c = db.query(...);
while (c.moveToNext()) {
    String name = c.getString(0);
    ...
}
click below button to copy code from our android learning website - android tutorial - team
SQLiteDatabase db = helper.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put("column", value);
...
db.insertOrThrow("table", null, cv);
click below button to copy code from our android learning website - android tutorial - team

Related Searches to Basic usage in Android Sqlite