我对数据库很陌生。
我正在尝试向表中添加列,我需要添加名为“0”、“1”、“2”等的列,直到“94169”。
我收到以下错误:
05-04 10:12:50.656: E/An droidRuntime(2022): FATAL EXCEPTION: main
05-04 10:12:50.656: E/AndroidRuntime(2022): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.koday/com.example.koday.MainActivity}: android.database.sqlite.SQLiteException: near "0": syntax error: ALTER TABLE data ADD COLUMN 0 INTEGER
05-04 10:12:50.656: E/AndroidRuntime(2022): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
05-04 10:12:50.656: E/AndroidRuntime(2022): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
05-04 10:12:50.656: E/AndroidRuntime(2022): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-04 10:12:50.656: E/AndroidRuntime(2022): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
05-04 10:12:50.656: E/AndroidRuntime(2022): at android.os.Handler.dispatchMessage(Handler.java:99)
05-04 10:12:50.656: E/AndroidRuntime(2022): at android.os.Looper.loop(Looper.java:130)
05-04 10:12:50.656: E/AndroidRuntime(2022): at android.app.ActivityThread.main(ActivityThread.java:3683)
05-04 10:12:50.656: E/AndroidRuntime(2022): at java.lang.reflect.Method.invokeNative(Native Method)
05-04 10:12:50.656: E/AndroidRuntime(2022): at java.lang.reflect.Method.invoke(Method.java:507)
05-04 10:12:50.656: E/AndroidRuntime(2022): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-04 10:12:50.656: E/AndroidRuntime(2022): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-04 10:12:50.656: E/AndroidRuntime(2022): at dalvik.system.NativeStart.main(Native Method)
05-04 10:12:50.656: E/AndroidRuntime(2022): Caused by: android.database.sqlite.SQLiteException: near "0": syntax error: ALTER TABLE data ADD COLUMN 0 INTEGER
05-04 10:12:50.656: E/AndroidRuntime(2022): at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)
05-04 10:12:50.656: E/AndroidRuntime(2022): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1763)
05-04 10:12:50.656: E/AndroidRuntime(2022): at com.example.koday.DataBaseHelper.aggiungi(DataBaseHelper.java:186)
05-04 10:12:50.656: E/AndroidRuntime(2022): at com.example.koday.MainActivity.onCreate(MainActivity.java:61)
05-04 10:12:50.656: E/AndroidRuntime(2022): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-04 10:12:50.656: E/AndroidRuntime(2022): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
05-04 10:12:50.656: E/AndroidRuntime(2022): ... 11 more
这是导致错误的代码片段:
public void aggiungi() {
SQLiteDatabase db = this.getWritableDatabase();
for (int i = 0; i < 94170; i++) {
db.execSQL("ALTER TABLE data ADD COLUMN " +Integer.toString(i)+" INTEGER");
}
db.close();
return;
}