Skip to content

Instantly share code, notes, and snippets.

@siddug
Last active August 29, 2015 14:13
Show Gist options
  • Save siddug/a29e200faf0b767774e1 to your computer and use it in GitHub Desktop.
Save siddug/a29e200faf0b767774e1 to your computer and use it in GitHub Desktop.
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);
}
//Once database is created, Create a table with columns - id, count, name
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT, count INTEGER, name TEXT);");
}
//Changing the version number in the database initialization calls for an upgrade of database. Drop or delete exisiting tables and create new one's
@Override
public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
db.execSQL("DROP TABLE IF EXISTS test");
onCreate(db);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment