How to insert data into SQLite database in Android?

I already saw an example of using SQlite in android ... but in this particular example, entries are inserted every time the application is launched. But I wanted to insert it only once and for all! any possibilities ???

+5
source share
4 answers

Insert values ​​into the method of onCreateyour SQLiteOpenHelper. It was called only when your database was created.

+5
source
   //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

+14
source

SQLite , , , , , .

SQLiteDatabaseHelper Application. , , , . , . , , onCreate.

+1

, , . sql OnClickListener - , , , , .

0

All Articles