我在项目中使用 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();
}
答案 0 :(得分:0)
在最后一个TEXT之后的create table语法中有一个额外的,
(逗号)。您需要删除它,因为它根据create table的语法无效。
使用此
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"+ ");";
答案 1 :(得分:0)
因为您的 DML 语句不正确,因此未创建第二个表。您必须从导致错误的语句中删除最后一个逗号。在表的最后一列后面不能是逗号,因为它是最后一列。
+ KEY_DOOR + " TEXT"+ ");
答案 2 :(得分: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();
}
}