Reputation: 273
Previous question: I'm following a SQLite tutorial and now I want to add two more columns to the table but there is error now? What is the problem here? Please help.
Logcat:
08-10 15:13:29.077: E/SQLiteLog(17055): (1) table country has no column named add
08-10 15:13:29.082: E/SQLiteDatabase(17055): Error inserting add=Feg dest=Fhd code=5495 cap=Egd name=A
08-10 15:13:29.082: E/SQLiteDatabase(17055): android.database.sqlite.SQLiteException: table country has no column named add (code 1): , while compiling: INSERT INTO country(add,dest,code,cap,name) VALUES (?,?,?,?,?)
08-10 15:13:29.082: E/SQLiteDatabase(17055): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
08-10 15:13:29.082: E/SQLiteDatabase(17055): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1012)
My SQLite java class
@Override
public void onCreate(SQLiteDatabase db) {
String createQuery = "CREATE TABLE country (_id integer primary key autoincrement,name, cap, code, dest, add);";
db.execSQL(createQuery);
}
Upvotes: 0
Views: 137
Reputation: 2368
please change this
db.execSQL("CREATE TABLE if not exists countryname(id INTEGER PRIMARY KEY AUTOINCREMENT," + " name" + " TEXT ," + " cape" + " TEXT," + " code" + " TEXT," + " dest" + " TEXT," + " mem" +" TEXT);");
into
db.execSQL("CREATE TABLE if not exists countryname(id INTEGER PRIMARY KEY AUTOINCREMENT," + " name" + " TEXT ," + " cape" + " TEXT," + " code" + " TEXT," + " dest" + " TEXT," + " mem" +" TEXT)");
you have ; after TEXT.. then please delete your old db and try it again it will work sure.
Upvotes: 2
Reputation: 6544
You can't use any reserved keyword as the column name. add is a reserved keyword, it can't be used as column name unless you quote it like 'add', "add" , add
or wrap it in bracket like [add].
Upvotes: 1
Reputation: 102743
Probably because "add" is a SQLite reserved word. You'll need to quote it, to indicate it's a column name.
INSERT INTO country(dest,code,[add],cap,name)
From the link, you can actually use any of 'add', "add", [add], or add
.
Upvotes: 0