I already saw an example of using SQlite in android...but in that particular example, records are inserted each time the app is ran..But i wanted to insert it only once and permanently! any possibilities???
4 Answers
//DB HANDLER CLASS
public void saveRecords(String info, int otherinfo, int greatinfo){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(STRING_COLUMNA, info); // inserting a string
values.put(STRING_COLUMNB, otherinfo); // inserting an int
values.put(STRING_COLUMNC, greatinfo); // inserting an int
// Inserting Row
db.insert(TABLE_NAME, null, values);
db.close(); // Closing database connection
}
Good luck!
1 Comment
Insert values in onCreate method of your SQLiteOpenHelper. It called only when your DB had been created.
1 Comment
SQLite Databases are persistent, so once you have the app on a phone or tablet and the DB is created, the records should stay in there until you delete the records or the whole database.
You should be calling the SQLiteDatabaseHelper from your Application class. So every time you open the app, it just looks for the database by the name you give it. If it can't find the database it creates it - If you have a record that you want inserted once and only once, you should create the records in the onCreate method.