0

I am trying to create a simple database but I receive this error:

09-09 12:42:14.750: E/AndroidRuntime(6971): Caused by: android.database.sqlite.SQLiteException: near "values": syntax error (code 1): , while compiling: create table values(_id integer primary key autoincrement, date text not null, screenTime integer not null );

I tried to look at other similar questions without finding a solution although I suspect my create statement to be incorrect but I am not sure. Below is my code.

public class MySQLiteHelper extends SQLiteOpenHelper {

    public static final String TABLE_VALUES = "values";
    public static final String COLUMN_ID = "_id";
    public static final String COLUMN_DATE = "date";
    public static final String COLUMN_SCREENTIME = "screenTime";

    private static final String DATABASE_NAME = "screenTime.db";
    private static final int DATABASE_VERSION = 1;

    // Database creation sql statement
    private static final String DATABASE_CREATE = "create table " + TABLE_VALUES
          + " ( " + COLUMN_ID + " integer primary key autoincrement, " 
          + COLUMN_DATE + " text not null, "
          + COLUMN_SCREENTIME + " integer not null );";

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

    @Override
    public void onCreate(SQLiteDatabase database) {
        database.execSQL(DATABASE_CREATE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.w(MySQLiteHelper.class.getName(),
        "Upgrading database from version " + oldVersion + " to "
            + newVersion + ", which will destroy all old data");
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_VALUES);
        onCreate(db);
    }
} 

1 Answer 1

1

VALUES is a keyword.

You could quote it, but it would be a better idea to use a different name. (Note: "values" is pretty much meaningless; every table has values in it.)

Sign up to request clarification or add additional context in comments.

1 Comment

I didn't knew that it is a keyword. Thanks for helping me out!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.