我正在尝试在android studio中创建SQLite数据库但我得到了下面的错误,我是android studio的初学者,我花了很长时间才找到解决方案。
错误是:
ActiveSheet.Buttons.Add(2676.75, 90, 131.25, 14.25).Caption = "Add Investments"
我的数据库处理程序代码是:
E/SQLiteLog: (1) near "_ItemName": syntax error
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: iq.nazaha.wissam.CoiApp, PID: 3786
java.lang.RuntimeException: Unable to start activity ComponentInfo{iq.nazaha.wissam.CoiApp/iq.nazaha.wissam.CoiApp.AddNewItemPage}: android.database.sqlite.SQLiteException: near "_ItemName": syntax error (code 1): , while compiling: CREATE TABLE items(_id INTEGER PRIMARY KEY _ItemName TEXT _ItemLocation TEXT _ItemPerson TEXT );
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: android.database.sqlite.SQLiteException: near "_ItemName": syntax error (code 1): , while compiling: CREATE TABLE items(_id INTEGER PRIMARY KEY _ItemName TEXT _ItemLocation TEXT _ItemPerson TEXT );
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1677)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1608)
at iq.nazaha.wissam.CoiApp.AppDB.onCreate(AppDB.java:32)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:251)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
at iq.nazaha.wissam.CoiApp.AppDB.dbToString(AppDB.java:65)
at iq.nazaha.wissam.CoiApp.AddNewItemPage.printDB(AddNewItemPage.java:52)
at iq.nazaha.wissam.CoiApp.AddNewItemPage.onCreate(AddNewItemPage.java:32)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
非常感谢你的帮助。
答案 0 :(得分:0)
在a CREATE TABLE
statement中,列按列分隔。
替换:
String query = " CREATE TABLE " + TABLE_ITEMSINFO + "(" +
COLUMN_ITEMID + " INTEGER PRIMARY KEY " +
COLUMN_ITEMNAME + " TEXT " +
COLUMN_ITEMLOCATION + " TEXT " +
COLUMN_ITEMPERSON + " TEXT " +
"); ";
使用:
String query = " CREATE TABLE " + TABLE_ITEMSINFO + "(" +
COLUMN_ITEMID + " INTEGER PRIMARY KEY, " +
COLUMN_ITEMNAME + " TEXT, " +
COLUMN_ITEMLOCATION + " TEXT, " +
COLUMN_ITEMPERSON + " TEXT " +
"); ";
答案 1 :(得分:0)
您忘记将commas
添加到SQL查询
String query = " CREATE TABLE " + TABLE_ITEMSINFO + "(" +
COLUMN_ITEMID + " INTEGER PRIMARY KEY, " +
COLUMN_ITEMNAME + " TEXT, " +
COLUMN_ITEMLOCATION + " TEXT, " +
COLUMN_ITEMPERSON + " TEXT " +
"); ";
db.execSQL(query);