final String CREATE_BASE_TABLE ="create table if not exists login ("
+ "email TEXT,"
+ "password TEXT,"
+ ");";

I have an android app that needs to check if there’s already a database available in the device, and if not, process some things and eventually create it.Then check if a particular table exists.

SQLiteDatabase db;
db = openOrCreateDatabase(
, null

If database exists and table exists simply read the data from the database if the data does exist.

Tip: For checking if a table Exists:

However, It is easy to find if a table exists or NOT,

Create a SQLiteDatabase object and have a call to query(…), the sql query string has select command. If the returned cursor is null then the table doesn’t exist.

SQLiteDatabase tempDatabase;

try {
tempDatabase =
SQLiteDatabase.openDatabase(DBPATH+DBNAME, null,


Cursor cur;

cur=tempDatabase.rawQuery("select * from table where id='"+idvar+";",null);



//our table doesn't exist, so we'll create one or take an action.


}catch (SQLiteException e) {
//our table doesn't exist, so we'll create one or take an action.

catch (SQLiteException e) {
//our database doesn't exist, so we'll create one or take an action.

Incoming search terms:

  • android sqlite query check for table
  • textview data is exist in sqlite table in android
  • table does not exists in sqlite in android
  • sqlite table exists android
  • sqlite table does not exist nwhile it is exist in android
  • sqlite checking for tables
  • sqlite check if table exists
  • openOrCreateDatabase create database if not exists
  • jquery phonegap how to validate if a database table exists
  • how to find table exists in database in android

Tagged with:

Filed under: Android

Like this post? Subscribe to my RSS feed and get loads more!