Reputation: 199
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
Reputation: 5743
SELECT COUNT() FROM sqlite_master WHERE name ='NAME_OF_YOUR_TABLE';
Upvotes: 7
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