我正在尝试清除具有自动增量键的表。
我试图做以下事情,我得到一个例外。
protected void clearSqliteSequenceTable(String table) {
String query = "delete from sqlite_sequence where name = business";
mDb.execSQL(query);
}
表名是business。我得到以下没有这样的列业务异常。
09-11 15:53:33.709: E/AndroidRuntime(20204): FATAL EXCEPTION: main
09-11 15:53:33.709: E/AndroidRuntime(20204): Process: com.xx.xxx, PID: 20204
09-11 15:53:33.709: E/AndroidRuntime(20204): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xx.xxx/com.xx.xxx.SplashActivity}: android.database.sqlite.SQLiteException: no such column: business (code 1): , while compiling: delete from sqlite_sequence where name = business
09-11 15:53:33.709: E/AndroidRuntime(20204): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
09-11 15:53:33.709: E/AndroidRuntime(20204): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
09-11 15:53:33.709: E/AndroidRuntime(20204): at android.app.ActivityThread.access$800(ActivityThread.java:135)
09-11 15:53:33.709: E/AndroidRuntime(20204): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
09-11 15:53:33.709: E/AndroidRuntime(20204): at android.os.Handler.dispatchMessage(Handler.java:102)
09-11 15:53:33.709: E/AndroidRuntime(20204): at android.os.Looper.loop(Looper.java:136)
09-11 15:53:33.709: E/AndroidRuntime(20204): at android.app.ActivityThread.main(ActivityThread.java:5001)
09-11 15:53:33.709: E/AndroidRuntime(20204): at java.lang.reflect.Method.invokeNative(Native Method)
09-11 15:53:33.709: E/AndroidRuntime(20204): at java.lang.reflect.Method.invoke(Method.java:515)
09-11 15:53:33.709: E/AndroidRuntime(20204): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
09-11 15:53:33.709: E/AndroidRuntime(20204): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
09-11 15:53:33.709: E/AndroidRuntime(20204): at dalvik.system.NativeStart.main(Native Method)
09-11 15:53:33.709: E/AndroidRuntime(20204): Caused by: android.database.sqlite.SQLiteException: no such column: business (code 1): , while compiling: delete from sqlite_sequence where name = business
09-11 15:53:33.709: E/AndroidRuntime(20204): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
09-11 15:53:33.709: E/AndroidRuntime(20204): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
09-11 15:53:33.709: E/AndroidRuntime(20204): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
09-11 15:53:33.709: E/AndroidRuntime(20204): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
09-11 15:53:33.709: E/AndroidRuntime(20204): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
09-11 15:53:33.709: E/AndroidRuntime(20204): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
09-11 15:53:33.709: E/AndroidRuntime(20204): at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1672)
09-11 15:53:33.709: E/AndroidRuntime(20204): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1603)
09-11 15:53:33.709: E/AndroidRuntime(20204): at com.xx.xxx.database.BaseDbAdapter.clearSqliteSequenceTable(BaseDbAdapter.java:65)
09-11 15:53:33.709: E/AndroidRuntime(20204): at com.xx.xxx.database.adapters.BusinessDbAdapter.clearSqliteSequenceTable(BusinessDbAdapter.java:149)
09-11 15:53:33.709: E/AndroidRuntime(20204): at com.xx.xxx.SplashActivity.insertDummyData(SplashActivity.java:79)
09-11 15:53:33.709: E/AndroidRuntime(20204): at com.xx.xxx.SplashActivity.onCreate(SplashActivity.java:51)
09-11 15:53:33.709: E/AndroidRuntime(20204): at android.app.Activity.performCreate(Activity.java:5231)
09-11 15:53:33.709: E/AndroidRuntime(20204): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-11 15:53:33.709: E/AndroidRuntime(20204): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
09-11 15:53:33.709: E/AndroidRuntime(20204): ... 11 more
答案 0 :(得分:3)
的“where”声明
name = business
尝试从表sqlite_sequence
中删除name
列等于假设的business
列。如果您尝试从名称列包含值“business”的sqlite_sequence
中删除,请尝试
String query = "DELETE FROM sqlite_sequence WHERE name = 'business'";
答案 1 :(得分:1)
只需修改您的查询
这
String query = "delete from sqlite_sequence where name = business";
到
String query = "delete from sqlite_sequence where name = \'business\' ";
我试过它的工作正常: - )
答案 2 :(得分:0)
试试这个
protected void clearSqliteSequenceTable(String table) {
String query = "delete from " + table;
mDb.execSQL(query);
}