0

error no such table not found在我的项目中使用了2 个数据库。一个工作正常,但另一个显示错误。

这是我的代码

public void onCreate(SQLiteDatabase db) {
    // TODO Auto-generated method stub
    String CREATE_ADDRESS = " CREATE TABLE " + TABLE_ADDRESS  + "(" + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"+ KEY_STATE + " TEXT," + KEY_CITY + " TEXT," + KEY_ZIPCODE + " TEXT," + KEY_STREET + " TEXT," + KEY_DOOR + " TEXT,"+ ");";      
    try{
        db.execSQL(CREATE_ADDRESS);
    }catch (SQLException e)
    {
        e.printStackTrace();
    }
}

我尝试使用此代码插入数据

public void addAddress(AddressList address)
{
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(KEY_STATE, address.getState());
    values.put(KEY_CITY, address.getCity());
    values.put(KEY_ZIPCODE, address.getZipcode());
    values.put(KEY_STREET, address.getStreet());
    values.put(KEY_DOOR, address.getDoor());
    db.insert(TABLE_ADDRESS,null, values);

    db.close();
}
4

3 回答 3

0

There is a extra , ( comma ) in your create table syntax after the last TEXT. You need to remove it because it is invalid as per create table's syntax.

use this

String CREATE_ADDRESS = " CREATE TABLE " + TABLE_ADDRESS  + "(" + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"+ KEY_STATE + " TEXT," + KEY_CITY + " TEXT," + KEY_ZIPCODE + " TEXT," + KEY_STREET + " TEXT," + KEY_DOOR + " TEXT"+ ");";
于 2013-04-03T11:13:37.573 回答
0

Because your DML statement is incorrect and then your second table is not created. You have to remove last comma from statement that causes error. Behind last column at table cannot be comma because it's last column.

+ KEY_DOOR + " TEXT"+ ");
于 2013-04-03T11:13:40.053 回答
0

您在最后一列中包含了,&;分号。尝试删除最后一个,;最后可能会修复您的错误。

public void onCreate(SQLiteDatabase db) {
 // TODO Auto-generated method stub
 String CREATE_ADDRESS = " CREATE TABLE " + TABLE_ADDRESS  + "(" + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"+ KEY_STATE + " TEXT," + KEY_CITY + " TEXT," + KEY_ZIPCODE + " TEXT," + KEY_STREET + " TEXT," + KEY_DOOR + "  TEXT" + ")";      
 try{
     db.execSQL(CREATE_ADDRESS);
 }catch (SQLException e)
 {
     e.printStackTrace();
 }
}
于 2016-08-30T02:01:06.833 回答