Originally Posted By: mcastagnolo
public class MySQLiteHelper extends SQLiteOpenHelper {
private Context context;
public MySQLiteHelper(Context context) {
super(context, "SimpleDB", null, 1);
this.context = context;
}
@Override
public void onCreate(SQLiteDatabase database) throws SQLException {
database.execSQL("create table SimpleTable(SimpleColumn integer not null)");
database.execSQL("insert into SimpleTable values(5)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// This method isn't necessary to implement, but is required to be here.
}
}
Driver Code
MySQLiteHelper dbHelper = new MySQLiteHelper(context);
dbHelper.getWriteableDatabase(); //Will execute the code in the onCreate method, creating the database and running the onCreate method.
'''Originally Posted By: mcastagnolo'''
public class MySQLiteHelper extends SQLiteOpenHelper {<br>private Context context;<br><br>public MySQLiteHelper(Context context) {<br>super(context, "SimpleDB", null, 1);<br>this.context = context;<br>}<br><br>@Override<br>public void onCreate(SQLiteDatabase database) throws SQLException {<br>database.execSQL("create table SimpleTable(SimpleColumn integer not null)");<br> database.execSQL("insert into SimpleTable values(5)");<br><br>}<br><br>@Override<br>public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {<br>// This method isn't necessary to implement, but is required to be here.<br>}<br><br>}<br><br>Driver Code<br><br>MySQLiteHelper dbHelper = new MySQLiteHelper(context);<br>dbHelper.getWriteableDatabase(); //Will execute the code in the onCreate method, creating the database and running the onCreate method.