Check if a table row exist - Android Database

Android examples for Database:SQL Query

Description

Check if a table row exist

Demo Code

/**//w ww.j a v  a2s.  c om
 * Copyright (c) 2014, German Neuroinformatics Node (G-Node)
 * Copyright (c) 2014, Shumail Mohy-ud-Din <shumailmohyuddin@gmail.com>
 * Copyright (c) 2013, Yasir Adnan <adnan.ayon@gmail.com> 
 * License: BSD-3 (See LICENSE)
 */
//package com.java2s;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import android.util.Log;

public class Main {
    public static SQLiteDatabase database;
    public static final String TABLE_ABSTRACT_FAVORITES = "ABSTRACT_FAVORITES";

    public static boolean abstractIsFavorite(String UUID) {
        Cursor cursor = database.rawQuery("select 1 from "
                + TABLE_ABSTRACT_FAVORITES + " where ABSTRACT_UUID like '%"
                + UUID + "%'", null);
        boolean exists = (cursor.getCount() > 0);
        cursor.close();
        return exists;
    }

}

Related Tutorials