sqlite返回:错误代码= 1,msg = near" TABLEtable_restaurants":语法错误,

时间:2013-07-26 21:50:38

标签: android sqlite syntax-error

public class RestaurantHelper extends SQLiteOpenHelper{

    public static final String TABLE_RESTAURANTS = "table_restaurants";
    public static final String COL_ID = "ID";
    public static final String COL_NAME = "NAME";
    public static final String COL_ADRESSE = "ADRESSE";
    public static final String COL_GENRE = "GENRE";
    public static final String COL_NOTES = "NOTES";
    public static final String COL_TELEPHONE = "TELEPHONE"; 

    private static final String CREATE_BDD = "CREATE TABLE" + TABLE_RESTAURANTS +
            " (" + COL_ID + "INTEGER PRIMARY KEY AUTOINCREMENT," + COL_NAME + "TEXT NOT NULL," +
            COL_ADRESSE + "TEXT NOT NULL," + COL_GENRE + "TEXT NOT NULL," + COL_NOTES + "TEXT NOT NULL," +
            COL_TELEPHONE + "TEXT NOT NULL);";


    public RestaurantHelper(Context context, String name,CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_BDD);

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE"+ TABLE_RESTAURANTS);
        onCreate(db);
    }

}
  

我是android的新手我收到此错误消息但我无法弄清楚   怎么了。感谢。

2 个答案:

答案 0 :(得分:2)

添加所需的空格。

private static final String CREATE_BDD = "CREATE TABLE " + TABLE_RESTAURANTS +
            " (" + COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + COL_NAME + " TEXT NOT NULL, " +
            COL_ADRESSE + " TEXT NOT NULL, " + COL_GENRE + " TEXT NOT NULL, " + COL_NOTES + " TEXT NOT NULL, " + COL_TELEPHONE + " TEXT NOT NULL);";

答案 1 :(得分:0)

你的“CREATE TABLE”应该有空格“CRATE TABLE”。注意空格配合