Android examples for Database:Table Exists
Check if table Is Exist in SQLiteDatabase
import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.util.Log; public class Main{ public final static String TAG = ""; /* w w w . j a va 2 s . co m*/ public static boolean tableIsExist(SQLiteDatabase db, String tableName) { boolean result = false; if (tableName == null) { return false; } Cursor cursor = null; try { // db = this.getReadableDatabase(); String sql = "select count(*) as c from Sqlite_master where type ='table' and name ='" + tableName.trim() + "' "; cursor = db.rawQuery(sql, null); if (cursor.moveToNext()) { int count = cursor.getInt(0); if (count > 0) { result = true; } } } catch (Exception e) { Log.e(TAG, "[tableIsExist method]error, e: ", e); } return result; } }