我正在尝试创建一个简单的数据库,但是我收到了这个错误:
09-09 12:42:14.750:E / AndroidRuntime(6971):引起:android.database.sqlite.SQLiteException:near" values":语法错误(代码1): ,同时编译:创建表值(_id整数主键自动增量,日期文本不为空,screenTime整数不为空);
我试图在没有找到解决方案的情况下查看其他类似的问题,尽管我怀疑我的创建声明不正确但我不确定。 以下是我的代码。
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);
}
}