Edward Sullen Edward Sullen - 1 year ago 91
Android Question

DROP TABLE not work in sqlite

I try to drop table programmatically nothing error show in logcat, but there has no any result :

Here my Database Helper class :

public class database1 extends SQLiteOpenHelper
private static final String DB_Name="database";
private static final int DB_Version=1;
private static final String tbl_arrival1="arrival1";
private static final String STRING_CREATE1 = "CREATE TABLE IF NOT EXISTS "+tbl_arrival1
+"f_date TEXT,"
+"o_rder NUMERIC,"
+"rem_com TEXT);";
public database1 (Context ctx)
public void onCreate(SQLiteDatabase database) {
public static class databaseQuery
public static void onCreate(SQLiteDatabase database)
database.execSQL("DROP TABLE IF EXISTS "+tbl_arrival1);

I use this database helper in content provider :

database1 DBHelper ;
public Uri insert(Uri uri, ContentValues values)
long row_id;
SQLiteDatabase sqlDB = DBHelper.getWritableDatabase();
row_id=sqlDB.insert(tbl_arrival1, null, values);
Uri _uri = ContentUris.withAppendedId(CONTENT_URI, row_id);
getContext().getContentResolver().notifyChange(_uri, null);
return _uri;
throw new SQLException("Failed to insert into "+uri);

The problem is that, the query drop table, is not working!

All suggestion and answer would be highly appreciated...


Answer Source

onCreate will work only once at time of creation once the database is created you should make use of onUpgrade() to drop table if any changes has been made to old version

EDIT http://www.vogella.com/articles/AndroidSQLite/article.html

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download