Course Hero Logo

cw2.docx - • Code elsewhere in your app creates an instance...

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 1 out of 1 page.

Code elsewhere in your app creates an instance of the database helper e.g.dbHelper = new DatabaseHelper(this);DatabaseHelper constructor runs telling superclass (SQLiteOpenHelper) the name and version ofdatabase e.g.super(context, DATABASE_NAME, null, 1);To gain access to the database you call getWriteableDatabase() or getReadableDatabase() to getthe SQLiteDatabase objectdatabase = getWritableDatabase();If the database doesn't already exist SQLiteOpenHelper calls onCreate() in your database helperto create the database e.g.db.execSQL("CREATE TABLE details (_id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT, dob TEXT,email TEXT);");The SQLiteDatabase object can then be used to query(), insert(), delete() etc the database
End of preview. Want to read the entire page?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
Wadhwa
Tags
Object Oriented Programming, Subroutine, Relational model

Unformatted text preview: •// Called by Persist1 to insert data entered by the user into •// the database. We could use raw SQL (execSQL) but it is better to • // use the purpose built insert method. •public long insertDetails(String name, String dob, String email) { • ContentValues rowValues = new ContentValues();• // Assemble row of data in the ContentValues object •rowValues.put("name", name); • rowValues.put("dob", dob);• rowValues.put("email", email); • // Note that if you use insert() rather than insertOrThrow any • // exception will get swallowed by the method• return database.insertOrThrow("details", null, rowValues); • }...
View Full Document

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture