Reputation: 25
I get a syntax error when I create a four rows table in my SQLite and I don't know why. This is my code.
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);
}
I don't know what i'm doing wrong.
Thanks in advance.
Upvotes: 0
Views: 71
Reputation: 152927
String CREATE_JUGADORS_TABLE1 = "CREATE TABLE_PRIMERO " + TABLE_PRIMERO + "("
+ KEY_ID + " INTEGER PRIMARY KEY,"
+ KEY_NAME + " TEXT,"
+ KEY_ALTURA + " TEXT,"
+ KEY_PARTIDO + " TEXT"
+ ")";
This should be something like
String CREATE_JUGADORS_TABLE1 = "CREATE TABLE " + TABLE_PRIMERO + "("
+ KEY_ID + " INTEGER PRIMARY KEY,"
+ KEY_NAME + " TEXT,"
+ KEY_ALTURA + " TEXT,"
+ KEY_PARTIDO + " TEXT"
+ ")";
The TABLE
is a keyword with a specific meaning.
Upvotes: 2