Android Sqlite数据库常见问题总结

xiaoxiao2021-02-28  105

当在SQLiteOpenHelper的实现类的onCreate中创建表格时,会遇到下列问题

@Override public void onCreate(SQLiteDatabase db) { db.execSQL("create table" + CrimeTable.Name + "(" + "_id integer primary key autoincrement," + CrimeTable.Cols.UUID + "," + CrimeTable.Cols.TITLE + "," + CrimeTable.Cols.DATE + "," + CrimeTable.Cols.SOLVED + ")" ); }

控制台打印的错误如下:

Caused by: android.database.sqlite.SQLiteException: near "tablecrimes": syntax error (code 1): , while compiling: create tablecrimes(_id integer primary key autoincrement,uuid,title,date,solved)

错误原因是:The missing space is what caused the issue as you can see in your first line of error report: 所以最重要的一点是:So yes the space between TABLE and TABLE_NAME is important !!!(在TABLE和TABLE_NAME中间的空格一定不要忘记)

转载请注明原文地址: https://www.6miu.com/read-54252.html

最新回复(0)