sayantan
sayantan

Reputation: 199

want to know if a table exists or not

i have a table MY_DATABASE_TABLE .. but i want to know if it exists or not

public boolean checkDataBase() {
        SQLiteDatabase checkDB = null;
        try {
            checkDB = SQLiteDatabase.openDatabase(MY_DATABASE_NAME, null,
                    SQLiteDatabase.OPEN_READONLY);
            checkDB.close();
        } catch (SQLiteException e) {
            // database doesn't exist yet.
        }
        return checkDB != null ? true : false;
    }

the above code didn't worked and always returned false

Upvotes: 2

Views: 4007

Answers (2)

mateusza
mateusza

Reputation: 5743

SELECT COUNT() FROM sqlite_master WHERE name ='NAME_OF_YOUR_TABLE';

Upvotes: 7

priit
priit

Reputation: 11

At the moment you're not checking if a table exists. You're opening a database. Check these: http://notes.theorbis.net/2008/12/check-if-datablase-table-exists.html http://groups.google.com/group/android-developers/browse_thread/thread/ffbe5bcdfbf5acaa

Upvotes: 1

Related Questions