update cache table via SQLiteDatabase - Android Database

Android examples for Database:Table Update

Description

update 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 int update(SQLiteDatabase db, String key, String value,
            String tag) {/*from  ww w .  j ava  2  s  . c o  m*/
        ContentValues values = new ContentValues();

        values.put(FIELD_SET_NAME, key);
        values.put(FIELD_VALUE, value);
        if (!TextUtils.isEmpty(tag))
            values.put(FIELD_TAG, tag);

        return db.update(TABLE_NAME, values, FIELD_SET_NAME + "= ? AND "
                + FIELD_VALUE + "=?", new String[] { key, value });
    }
}

Related Tutorials