独学でアンドロイドのアプリ開発をしています。
アプリにSQLiteを使いたいのですが、正しくSQL構文を書いているはずなのにエラーを起こしてしまいます。
以下エラー該当箇所です。
Java
1 private static final String SQL_CREATE_ENTRIES = 2 "CREATE TABLE " + TABLE_NAME + " (" + 3 _ID + " INTEGER PRIMARY KEY," + 4 COLUMN_NAME_TIMES + " TEXT," + 5 COLUMN_NAME_COLOR + " TEXT," + 6 COLUMN_NAME_STAMPS + " INTEGER)"; 7 8 private static final String SQL_DELETE_ENTRIES = 9 "DROP TABLE IF EXISTS " + TABLE_NAME;
エラー内容は以下の通りです。
<database name>, <table definition name> or IF expected, got 'plan'
コード全体がこちらです。
Java
1package com.example.test3; 2 3import android.content.Context; 4import android.content.ContentValues; 5import android.database.sqlite.SQLiteDatabase; 6import android.database.sqlite.SQLiteOpenHelper; 7 8public class TestOpenHelper extends SQLiteOpenHelper { 9 10 public static final int DATABASE_VERSION = 3; 11 12 public static final String DATABASE_NAME = "Plans.db"; 13 private static final String TABLE_NAME = "plan"; 14 private static final String _ID = "_id"; 15 private static final String COLUMN_NAME_TIMES = "time"; 16 private static final String COLUMN_NAME_COLOR = "color"; 17 private static final String COLUMN_NAME_STAMPS = "stamps"; 18 19 private static final String SQL_CREATE_ENTRIES = 20 "CREATE TABLE " + TABLE_NAME + " (" + 21 _ID + " INTEGER PRIMARY KEY," + 22 COLUMN_NAME_TIMES + " TEXT," + 23 COLUMN_NAME_COLOR + " TEXT," + 24 COLUMN_NAME_STAMPS + " INTEGER)"; 25 26 private static final String SQL_DELETE_ENTRIES = 27 "DROP TABLE IF EXISTS " + TABLE_NAME; 28 29 TestOpenHelper(Context context){ 30 super(context, DATABASE_NAME, null, DATABASE_VERSION); 31 } 32 33 @Override 34 public void onCreate(SQLiteDatabase db){ 35 db.execSQL( 36 SQL_CREATE_ENTRIES 37 ); 38 39 saveData(db, "0:00", null, 0); 40 saveData(db, "1:00", null, 0); 41 saveData(db, "2:00", null, 0); 42 saveData(db, "3:00", null, 0); 43 saveData(db, "4:00", null, 0); 44 saveData(db, "5:00", null, 0); 45 saveData(db, "6:00", null, 0); 46 saveData(db, "7:00", null, 0); 47 saveData(db, "8:00", null, 0); 48 saveData(db, "9:00", null, 0); 49 saveData(db, "10:00", null, 0); 50 saveData(db, "11:00", null, 0); 51 saveData(db, "12:00", null, 0); 52 saveData(db, "13:00", null, 0); 53 saveData(db, "14:00", null, 0); 54 saveData(db, "15:00", null, 0); 55 saveData(db, "16:00", null, 0); 56 saveData(db, "17:00", null, 0); 57 saveData(db, "18:00", null, 0); 58 saveData(db, "19:00", null, 0); 59 saveData(db, "20:00", null, 0); 60 saveData(db, "21:00", null, 0); 61 saveData(db, "22:00", null, 0); 62 saveData(db, "23:00", null, 0); 63 64 } 65 66 @Override 67 public void onUpgrade(SQLiteDatabase db, 68 int oldVersion, int newVersion){ 69 db.execSQL( 70 SQL_DELETE_ENTRIES 71 ); 72 onCreate(db); 73 } 74 75 public void onDowngrade(SQLiteDatabase db, 76 int oldVersion, int newVersion){ 77 onUpgrade(db, oldVersion, newVersion); 78 } 79 80 public void saveData(SQLiteDatabase db, String times, String color, int stamps){ 81 ContentValues values = new ContentValues(); 82 values.put("times", times); 83 values.put("color", color); 84 values.put("int", stamps); 85 86 db.insert("plan", null, values); 87 } 88} 89
どうすればエラーを解消できますでしょうか?