Reputation: 2113
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);
}
}
Upvotes: 0
Views: 104