- Create SQLite database.
Define a class derived from
SQLiteOpenHelper:
public class SDBH extends SQLiteOpenHelper {
private static final String DB_NAME = "students.db";
private static final int DB_VERSION = 1;
}
- Create SQLite table:
db.execSQL("create table students(" +
"name text, grade integer, gender text);");
- Insert row into table:
ContentValues studentValues = new ContentValues( );
studentValues.put("name", name);
studentValues.put("grade", grade);
studentValues.put("gender", gender);
db.insert("students", null, studentValues);
- Create Cursor to view query results:
Cursor cursor = db.query("students",
new String[ ] {"name", "grade", "gender"},
null, null, null, null, null);
The five null arguments correspond to these parameters:
selection selectionArgs groupBy having orderBy
- Methods to position cursor within result set:
cursor.moveToFirst( )
cursor.moveToNext( )
cursor.moveToPrevious( )
cursor.moveToLast( )
- Methods to obtain field values from current cursor position:
cursor.getDouble(columnIndex)
cursor.getInt(columnIndex)
cursor.getString(columnIndex)