insert data to cache table via SQLiteDatabase - Android Database

Android examples for Database:SQL Insert

Description

insert data to cache table via SQLiteDatabase

Demo Code


//package com.book2s;
import android.content.ContentValues;

import android.database.sqlite.SQLiteDatabase;
import android.text.TextUtils;

public class Main {
    static final String TABLE_NAME = "cache_data";
    static final String FIELD_SET_NAME = "set_name";
    static final String FIELD_TAG = "tag";
    static final String FIELD_VALUE = "value";

    public static boolean insert(SQLiteDatabase db, String key,
            String value, String tag) {
        ContentValues values = new ContentValues();

        values.put(FIELD_SET_NAME, key);
        values.put(FIELD_VALUE, value);//from  w  w  w . j  a v a 2  s . c  om

        if (!TextUtils.isEmpty(tag))
            values.put(FIELD_TAG, tag);

        return db.insert(TABLE_NAME, null, values) == -1 ? false : true;
    }
}

Related Tutorials