check database Table Exist by counting Cursor - Android Database

Android examples for Database:Cursor

Description

check database Table Exist by counting Cursor

Demo Code


//package com.book2s;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class Main {
    public static boolean checkTableExist(SQLiteDatabase db,
            String tableName) {//  ww  w  .ja va  2 s .c o  m
        Cursor c = db.rawQuery(
                "SELECT * FROM sqlite_master WHERE type='table' "
                        + "AND name='" + tableName + "';", null);
        try {
            return c.getCount() > 0;
        } finally {
            c.close();
        }
    }
}

Related Tutorials