creation of table on SQLiteDatabase fails
I am adding a new table on my database with this code:
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE" + QRCODE_LINK + "(" +
"ID" + "INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "Title" + "text,"
+ "HISTORY" + " text not null);" );
}
However, i am getting an error whenever i'm inserting a data because the table, according to the logs, does not exist. Did i miss something when i created the table?
Here is the log:
10-17 13:56:55.362: ERROR/Database(6791): Error inserting inhistory=1 qr_url=data1
10-17 13:56:55.362: ERROR/Database(6791): android.database.sqlite.SQLiteException: no such table: qrcode_link: , while compiling: INSERT INTO qrcode_link(inhistory, qr_url) VALUES(?, ?);
10-17 13:56:55.362: ERROR开发者_如何学Go/Database(6791): at android.database.sqlite.SQLiteProgram.native_compile(Native Method)
10-17 13:56:55.362: ERROR/Database(6791): at android.database.sqlite.SQLiteProgram.compile(SQLiteProgram.java:110)
10-17 13:56:55.362: ERROR/Database(6791): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59)
10-17 13:56:55.362: ERROR/Database(6791): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:41)
10-17 13:56:55.362: ERROR/Database(6791): at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1123)
10-17 13:56:55.362: ERROR/Database(6791): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1509)
10-17 13:56:55.362: ERROR/Database(6791): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1382)
they didn't have space after Create Table
You need to add some spacing before telling if it is integer or text.
It's correct in you History
column, but entry in your ID
column you actually have IDINTEGER
and in you Title
column you have Titletext
.
@Override public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE" + QRCODE_LINK + "(" +
"ID" + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "Title" + " text,"
+ "HISTORY" + " text not null);" ); }
Hope this makes sense:)
EDIT
Okay Read the code again. You need spacing when creating your Table "CREATE TABLE " + QRCODE_LINK + "("
and so on.
Actualy as Agriesean said. But without the other corrections you will not have the correct columns.
精彩评论