You can refer my following code You can customize this code as a library for sqllite
package com.zindio.app;
import java.util.ArrayList;
import java.util.List;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DataBaseHandler extends SQLiteOpenHelper {
// All Static variables
// Database Version
private static final int DATABASE\_VERSION = 1;
// Database Name
private static final String DATABASE\_NAME = "menuitemsordered";
// Ordered Menu Items table name
private static final String TABLE\_MENUITEMS = "menuitems";
// Ordered Menu Items Table Columns names
private static final String KEY\_UNIQUEID = "id";
private static final String KEY\_MENUID = "menuid";
private static final String KEY\_NAME = "name";
private static final String KEY\_PRICE = "price";
private static final String KEY\_DESCRIPTION = "description";
public DataBaseHandler(Context context) {
super(context, DATABASE\_NAME, null, DATABASE\_VERSION);
}
// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE\_MENUITEMS\_TABLE = "CREATE TABLE " + TABLE\_MENUITEMS + "("
+ KEY\_UNIQUEID + " INTEGER PRIMARY KEY," + KEY\_MENUID
+ " TEXT," + KEY\_NAME + " TEXT," + KEY\_PRICE + " TEXT,"
+ KEY\_DESCRIPTION + " TEXT" + ")";
db.execSQL(CREATE\_MENUITEMS\_TABLE);
}
// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + TABLE\_MENUITEMS);
// Create tables again
onCreate(db);
}
/\*\*
\* All CRUD(Create, Read, Update, Delete) Operations
\*/
// Adding new ordered item
Long additem(ordereditems item) {
Long lInsertedID;
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY\_NAME, item.getName());
values.put(KEY\_PRICE, item.getamount());
values.put(KEY\_MENUID, item.getmenuitemid());
// Inserting Row
lInsertedID = db.insert(TABLE\_MENUITEMS, null, values);
db.close(); // Closing database connection
return lInsertedID;
}
// Getting single contact
ordereditems getitem(int id) {
SQLiteDatabase db = this.getReadableDatabase();
// private static final String KEY\_UNIQUEID = "id";
// private static final String KEY\_MENUID = "menuid