I'm trying to create a table in my sqlite database, but there seems to be a syntax error in the creation method that is causing the application to crash once it reaches an activity that requires it. I'm still relatively new to Sqlite so any advice or assistance would be greatly appreciated.
Here is the error message:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.liam.ca3/com.example.liam.QuickDraw.MainActivity}: android.database.sqlite.SQLiteException: near "2015": syntax error (code 1): , while compiling: create table tableImages(id integer primary key autoincrement, 2015-03-26 TEXT,title TEXT,rating TEXT,size TEXT,image BLOB)
And here is the handler class for my database
public class DatabaseHandler extends SQLiteOpenHelper{
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "imagedb";
public static final String TABLE_IMAGES = "tableImages";
public static final String tID = "id";
public static final String tTITLE = "title";
//SimpleDateFormat object defined to sort dates into an easily readable style. This is then used to act as the value format for tDate
public static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
public static final String tDate = sdf.format(new Date());
public static final String tRating = "rating";
public static final String tSize = "size";
public static final String tIMAGE = "image";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
// Database creation sql statement
private static final String DATABASE_CREATE = "create table "
+ TABLE_IMAGES + "(" + tID
+ " integer primary key autoincrement, " + tDate + " TEXT," + tTITLE
+ " TEXT," + tRating + " TEXT," + tSize + " TEXT,"
+ tIMAGE + " BLOB" + ")";
@Override
public void onCreate(SQLiteDatabase database) {
database.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(DatabaseHandler.class.getName(),
"Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + TABLE_IMAGES);
onCreate(db);
}
}
Aucun commentaire:
Enregistrer un commentaire