I did exactly the same thing what bucky did, even then the app did not run.When I typed in the EditText and then clicked add, the logcat showed busy for a long time but it did not display the table, i thought there was problem in the SQL code so i literally copied the code by bucky, then also i cant run the app. I am putting my java code for the dbmanager.java... see if there is any mistakes. Also the code from MySQL databases tutorial like use of  single quotes to enclose text (' ' ) and use of AUTO_INCREMENT instead of AUTOINCREMENT gave errors. So is SQLite slightly different from MySQL in phpmyAdmin? Please help anyonw.. thanks in advance..


package com.kushagra.databsehandling;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class dbManager extends SQLiteOpenHelper {
    private static final int DATABASE_VERSION=1;
    private static final String DATABASE_NAME="itemsDatabase.db";
    private static final String TABLE_NAME="itemsList";
    public static final String COLUMN_ID="_id";
    public static final String COLUMN_ITEM="item";

    public dbManager(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context,DATABASE_NAME, factory, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String query="CREATE TABLE " + TABLE_NAME + "(" +
                COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT "+
                COLUMN_ITEM + " TEXT " +
                ");";
        db.execSQL(query);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
        onCreate(db);
    }

    public void addProduct(Product item){
        SQLiteDatabase db=getWritableDatabase();
        ContentValues values=new ContentValues();
        values.put(COLUMN_ITEM,item.get_item());
        db.insert(TABLE_NAME,null,values);
        db.close();
        databaseString();
    }

    public void deleteProduct(String item){
        SQLiteDatabase db=getWritableDatabase();
        db.execSQL("DELETE FROM " + TABLE_NAME + " WHERE "+ COLUMN_ITEM + "=\"" + item + "\";");
        db.close();

    }

    public String databaseString(){
        SQLiteDatabase db=getWritableDatabase();
        String query="SELECT * FROM " + TABLE_NAME + " WHERE 1";
        Cursor c=db.rawQuery(query,null);
        c.moveToFirst();
        String dbString="";
        while(!c.isAfterLast()){
            if(c.getString(c.getColumnIndex("item"))!=null){
                dbString+=c.getString(c.getColumnIndex("item"));
                dbString+="\n";
            }
        }
        db.close();
        return dbString;
    }
}