 
                http://hmkcode.com/android-simple-sqlite-database-tutorial/
http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/
http://chintankhetiya.wordpress.com/2013/06/01/sqlite-database-example/
http://www.techotopia.com/index.php/An_Android_SQLite_Database_Tutorial <<== this is perfect
Objectives:
What we are building here?
We will build an App that can store & retrieve books title and author name.
We want to create the following:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | packagecom.hmkcode.android.model;publicclassBook {    privateintid;    privateString title;    privateString author;    publicBook(){}    publicBook(String title, String author) {        super();        this.title = title;        this.author = author;    }    //getters & setters    @Override    publicString toString() {        return"Book [id="+ id + ", title="+ title + ", author="+ author                + "]";    }} | 
The recommended method to create a new SQLite database is to create a subclass ofSQLiteOpenHelper and override the onCreate() method, in which you can execute a SQLite command to create tables in the database.
This is the main step.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | packagecom.hmkcode.android.sqlite;importandroid.content.Context;importandroid.database.sqlite.SQLiteDatabase;importandroid.database.sqlite.SQLiteOpenHelper;publicclassMySQLiteHelper extendsSQLiteOpenHelper {    // Database Version    privatestaticfinalintDATABASE_VERSION = 1;    // Database Name    privatestaticfinalString DATABASE_NAME = "BookDB";    publicMySQLiteHelper(Context context) {        super(context, DATABASE_NAME, null, DATABASE_VERSION);      }    @Override    publicvoidonCreate(SQLiteDatabase db) {        // SQL statement to create book table        String CREATE_BOOK_TABLE = "CREATE TABLE books ( "+                "id INTEGER PRIMARY KEY AUTOINCREMENT, "+                 "title TEXT, "+                "author TEXT )";        // create books table        db.execSQL(CREATE_BOOK_TABLE);    }    @Override    publicvoidonUpgrade(SQLiteDatabase db, intoldVersion, intnewVersion) {        // Drop older books table if existed        db.execSQL("DROP TABLE IF EXISTS books");        // create fresh books table        this.onCreate(db);    }} | 
Define static constants for table & columns names;
    // Books table name
    private static final String TABLE_BOOKS = "books";
    // Books Table Columns names
    private static final String KEY_ID = "id";
    private static final String KEY_TITLE = "title";
    private static final String KEY_AUTHOR = "author";
    private static final String[] COLUMNS = {KEY_ID,KEY_TITLE,KEY_AUTHOR};Notice:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | publicvoidaddBook(Book book){                //for logging        Log.d("addBook", book.toString());         // 1. get reference to writable DB        SQLiteDatabase db = this.getWritableDatabase();        // 2. create ContentValues to add key "column"/value        ContentValues values = newContentValues();        values.put(KEY_TITLE, book.getTitle()); // get title         values.put(KEY_AUTHOR, book.getAuthor()); // get author        // 3. insert        db.insert(TABLE_BOOKS, // table                null, //nullColumnHack                values); // key/value -> keys = column names/ values = column values        // 4. close        db.close();     } | 
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | publicBook getBook(intid){    // 1. get reference to readable DB    SQLiteDatabase db = this.getReadableDatabase();    // 2. build query    Cursor cursor =             db.query(TABLE_BOOKS, // a. table            COLUMNS, // b. column names            " id = ?", // c. selections             newString[] { String.valueOf(id) }, // d. selections args            null, // e. group by            null, // f. having            null, // g. order by            null); // h. limit    // 3. if we got results get the first one    if(cursor != null)        cursor.moveToFirst();    // 4. build book object    Book book = newBook();    book.setId(Integer.parseInt(cursor.getString(0)));    book.setTitle(cursor.getString(1));    book.setAuthor(cursor.getString(2));    //log Log.d("getBook("+id+")", book.toString());    // 5. return book    returnbook;} | 
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | publicList<Book> getAllBooks() {       List<Book> books = newLinkedList<Book>();       // 1. build the query       String query = "SELECT  * FROM "+ TABLE_BOOKS;       // 2. get reference to writable DB       SQLiteDatabase db = this.getWritableDatabase();       Cursor cursor = db.rawQuery(query, null);       // 3. go over each row, build book and add it to list       Book book = null;       if(cursor.moveToFirst()) {           do{               book = newBook();               book.setId(Integer.parseInt(cursor.getString(0)));               book.setTitle(cursor.getString(1));               book.setAuthor(cursor.getString(2));               // Add book to books               books.add(book);           } while(cursor.moveToNext());       }       Log.d("getAllBooks()", books.toString());       // return books       returnbooks;   } | 
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | publicintupdateBook(Book book) {    // 1. get reference to writable DB    SQLiteDatabase db = this.getWritableDatabase();    // 2. create ContentValues to add key "column"/value    ContentValues values = newContentValues();    values.put("title", book.getTitle()); // get title     values.put("author", book.getAuthor()); // get author    // 3. updating row    inti = db.update(TABLE_BOOKS, //table            values, // column/value            KEY_ID+" = ?", // selections            newString[] { String.valueOf(book.getId()) }); //selection args    // 4. close    db.close();    returni;} | 
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | publicvoiddeleteBook(Book book) {        // 1. get reference to writable DB        SQLiteDatabase db = this.getWritableDatabase();        // 2. delete        db.delete(TABLE_BOOKS, //table name                KEY_ID+" = ?",  // selections                newString[] { String.valueOf(book.getId()) }); //selections args        // 3. close        db.close();        //log    Log.d("deleteBook", book.toString());    } | 
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | packagecom.hmkcode.android.sqlite;importjava.util.LinkedList;importjava.util.List;importcom.hmkcode.android.model.Book;importandroid.content.ContentValues;importandroid.content.Context;importandroid.database.Cursor;importandroid.database.sqlite.SQLiteDatabase;importandroid.database.sqlite.SQLiteOpenHelper;importandroid.util.Log;publicclassMySQLiteHelper extendsSQLiteOpenHelper {    // Database Version    privatestaticfinalintDATABASE_VERSION = 1;    // Database Name    privatestaticfinalString DATABASE_NAME = "BookDB";    publicMySQLiteHelper(Context context) {        super(context, DATABASE_NAME, null, DATABASE_VERSION);      }    @Override    publicvoidonCreate(SQLiteDatabase db) {        // SQL statement to create book table        String CREATE_BOOK_TABLE = "CREATE TABLE books ( "+                "id INTEGER PRIMARY KEY AUTOINCREMENT, "+                 "title TEXT, "+                "author TEXT )";        // create books table        db.execSQL(CREATE_BOOK_TABLE);    }    @Override    publicvoidonUpgrade(SQLiteDatabase db, intoldVersion, intnewVersion) {        // Drop older books table if existed        db.execSQL("DROP TABLE IF EXISTS books");        // create fresh books table        this.onCreate(db);    }    //---------------------------------------------------------------------    /**     * CRUD operations (create "add", read "get", update, delete) book + get all books + delete all books     */    // Books table name    privatestaticfinalString TABLE_BOOKS = "books";    // Books Table Columns names    privatestaticfinalString KEY_ID = "id";    privatestaticfinalString KEY_TITLE = "title";    privatestaticfinalString KEY_AUTHOR = "author";    privatestaticfinalString[] COLUMNS = {KEY_ID,KEY_TITLE,KEY_AUTHOR};    publicvoidaddBook(Book book){        Log.d("addBook", book.toString());        // 1. get reference to writable DB        SQLiteDatabase db = this.getWritableDatabase();        // 2. create ContentValues to add key "column"/value        ContentValues values = newContentValues();        values.put(KEY_TITLE, book.getTitle()); // get title         values.put(KEY_AUTHOR, book.getAuthor()); // get author        // 3. insert        db.insert(TABLE_BOOKS, // table                null, //nullColumnHack                values); // key/value -> keys = column names/ values = column values        // 4. close        db.close();     }    publicBook getBook(intid){        // 1. get reference to readable DB        SQLiteDatabase db = this.getReadableDatabase();        // 2. build query        Cursor cursor =                 db.query(TABLE_BOOKS, // a. table                COLUMNS, // b. column names                " id = ?", // c. selections                 newString[] { String.valueOf(id) }, // d. selections args                null, // e. group by                null, // f. having                null, // g. order by                null); // h. limit        // 3. if we got results get the first one        if(cursor != null)            cursor.moveToFirst();        // 4. build book object        Book book = newBook();        book.setId(Integer.parseInt(cursor.getString(0)));        book.setTitle(cursor.getString(1));        book.setAuthor(cursor.getString(2));        Log.d("getBook("+id+")", book.toString());        // 5. return book        returnbook;    }    // Get All Books    publicList<Book> getAllBooks() {        List<Book> books = newLinkedList<Book>();        // 1. build the query        String query = "SELECT  * FROM "+ TABLE_BOOKS;        // 2. get reference to writable DB        SQLiteDatabase db = this.getWritableDatabase();        Cursor cursor = db.rawQuery(query, null);        // 3. go over each row, build book and add it to list        Book book = null;        if(cursor.moveToFirst()) {            do{                book = newBook();                book.setId(Integer.parseInt(cursor.getString(0)));                book.setTitle(cursor.getString(1));                book.setAuthor(cursor.getString(2));                // Add book to books                books.add(book);            } while(cursor.moveToNext());        }        Log.d("getAllBooks()", books.toString());        // return books        returnbooks;    }     // Updating single book    publicintupdateBook(Book book) {        // 1. get reference to writable DB        SQLiteDatabase db = this.getWritableDatabase();        // 2. create ContentValues to add key "column"/value        ContentValues values = newContentValues();        values.put("title", book.getTitle()); // get title         values.put("author", book.getAuthor()); // get author        // 3. updating row        inti = db.update(TABLE_BOOKS, //table                values, // column/value                KEY_ID+" = ?", // selections                newString[] { String.valueOf(book.getId()) }); //selection args        // 4. close        db.close();        returni;    }    // Deleting single book    publicvoiddeleteBook(Book book) {        // 1. get reference to writable DB        SQLiteDatabase db = this.getWritableDatabase();        // 2. delete        db.delete(TABLE_BOOKS,                KEY_ID+" = ?",                newString[] { String.valueOf(book.getId()) });        // 3. close        db.close();        Log.d("deleteBook", book.toString());    }} | 
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | packagecom.hmkcode.android;importjava.util.List;importcom.hmkcode.android.model.Book;importcom.hmkcode.android.sqlite.MySQLiteHelper;importandroid.os.Bundle;importandroid.app.Activity;publicclassMainActivity extendsActivity {    @Override    protectedvoidonCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        MySQLiteHelper db = newMySQLiteHelper(this);        /**         * CRUD Operations         * */        // add Books        db.addBook(newBook("Android Application Development Cookbook", "Wei Meng Lee"));           db.addBook(newBook("Android Programming: The Big Nerd Ranch Guide", "Bill Phillips and Brian Hardy"));               db.addBook(newBook("Learn Android App Development", "Wallace Jackson"));        // get all books        List<Book> list = db.getAllBooks();        // delete one book        db.deleteBook(list.get(0));        // get all books        db.getAllBooks();    }} | 
LogCat view