创建表语法错误SQLite

时间:2014-02-20 12:05:43

标签: sqlite syntax-error create-table

当我在SQLite中创建一个四行表时出现语法错误,我不知道为什么。这是我的代码。

 private static final String TABLE_PRIMERO = "jugadors";

// Jugadors Table Columns names
private static final String KEY_ID = "id";
private static final String KEY_NAME = "name";
private static final String KEY_ALTURA = "altura";
private static final String KEY_PARTIDO = "partido";

int oldVersion=1;

public DatabaseHandler(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {

    String CREATE_JUGADORS_TABLE1 = "CREATE TABLE_PRIMERO " + TABLE_PRIMERO + "("
            + KEY_ID + " INTEGER PRIMARY KEY,"
            + KEY_NAME + " TEXT,"
            + KEY_ALTURA + " TEXT,"
            + KEY_PARTIDO + " TEXT"
            + ")";
    db.execSQL(CREATE_JUGADORS_TABLE1);


}

//Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // Drop older table if existed
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_PRIMERO);

    // Create tables again
    onCreate(db);
}

我不知道我做错了什么。

提前致谢。

1 个答案:

答案 0 :(得分:2)

String CREATE_JUGADORS_TABLE1 = "CREATE TABLE_PRIMERO " + TABLE_PRIMERO + "("
        + KEY_ID + " INTEGER PRIMARY KEY,"
        + KEY_NAME + " TEXT,"
        + KEY_ALTURA + " TEXT,"
        + KEY_PARTIDO + " TEXT"
        + ")";

这应该是

String CREATE_JUGADORS_TABLE1 = "CREATE TABLE " + TABLE_PRIMERO + "("
        + KEY_ID + " INTEGER PRIMARY KEY,"
        + KEY_NAME + " TEXT,"
        + KEY_ALTURA + " TEXT,"
        + KEY_PARTIDO + " TEXT"
        + ")";

TABLE是具有特定含义的关键字。