Tuesday, July 19, 2011

android.database.sqlite.SQLiteException: table already exists

Hi guys,
Many times I have faced this problem when I tried to call the db.execSQL(CREATE_TABLE) after  openOrCreateDatabase(DATABASE_NAME,Context.MODE_PRIVATE, null); function. And generally it happens when you are trying to create a table in the same database which already have one or more table in i, other situation is when you are running the same program again and again and the same table is already in the database. So to solve this issue you just need to modify your CREATE_TABLE string(which is creating the table).
Generally we directly use “create table TABLE_NAME” which create problem, so instead of it just add one more thing in it, now create table using string “create table if not exists TABLE_NAME”. It will solve your problem. Hope it will help you.

2 comments:

Anonymous said...

Did help, thanks!

apilyugina said...

thanks a lot! another good article on the topic http://www.enterra-inc.com/techzone/handling_sql_issues/