Skip to content

Instantly share code, notes, and snippets.

//while moving cursor to the last, read 3rd column data (index 2) which in our database is (name - string)
while(c.moveToNext()){s2=c.getString(2);}
SQLiteDatabase readDB= db.getReadableDatabase();
Cursor c = readDB.rawQuery("SELECT * from test", null);
// create an instance of SQLiteDatabase using getWritableDatabase()
SQLiteDatabase writeDB = db.getWritableDatabase();
// Use execSQL function to pass SQL insert statement to execute
writeDB.execSQL("INSERT into test (count, name) values(0,'sample')");
DbManager db = new DbManager(this.getApplicationContext());
public class DbManager extends SQLiteOpenHelper{
//Database name
private static final String dbName = "sampleData";
private static final Integer version = 1;
//initializer
public DbManager(Context context) {
super(context, dbName, null, version);
}