0

上一个问题:我正在关注 SQLite 教程,现在我想在表中再添加两列,但现在出现错误?这里有什么问题?请帮忙。

日志猫:

   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)

我的 SQLite java 类

@Override
    public void onCreate(SQLiteDatabase db) {
        String createQuery = "CREATE TABLE country (_id integer primary key autoincrement,name, cap, code, dest, add);";     
        db.execSQL(createQuery);        
    }
4

3 回答 3

2

请改变这个

 db.execSQL("CREATE TABLE if not exists countryname(id INTEGER PRIMARY KEY AUTOINCREMENT,"
            + " name"
            + " TEXT ,"
            + " cape"
            + " TEXT,"
            + " code" 
            + " TEXT,"
            + " dest" 
            + " TEXT,"
            + " mem"
            +" TEXT);");   

进入

  db.execSQL("CREATE TABLE if not exists countryname(id INTEGER PRIMARY KEY AUTOINCREMENT,"
            + " name"
            + " TEXT ,"
            + " cape"
            + " TEXT,"
            + " code" 
            + " TEXT,"
            + " dest" 
            + " TEXT,"
            + " mem"
            +" TEXT)");   

你有在 TEXT 之后.. 然后请删除您的旧数据库并再试一次,它肯定会工作。

于 2013-08-10T06:43:05.277 回答
1

您不能使用任何保留关键字作为列名。add 是一个保留关键字,它不能用作列名,除非你像 'add', "add" 一样引用它,add或者像 [add] 一样将它包裹在括号中。

于 2013-08-10T06:46:54.487 回答
0

可能是因为“add”是SQLite 保留字。您需要引用它,以表明它是列名。

INSERT INTO country(dest,code,[add],cap,name)

从链接中,您实际上可以使用“添加”、“添加”、[添加] 或add.

于 2013-08-10T06:42:52.880 回答