public class DBhelper扩展了SQLiteOpenHelper {
public static final String TABLE_EVENT = "event";
public static final String EVENT_ID= "_id";
public static final String EVENT_NAME = "name";
public static final String EVENT_DATE = "date";
public static final String EVENT_DESCRIPTION ="description";
static final String DB_NAME = "DBEVENT";
static final int DB_VERSION = 1;
private static final String CREATE_TABLE = "CREATE TABLE " + TABLE_EVENT + " (" +
EVENT_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
EVENT_NAME + " text not null, " +
EVENT_DATE + " text not null, "+
EVENT_DESCRIPTION + " text not null "+
" )";
public DBhelper(Context context) {
super(context, DB_NAME, null,DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS " + TABLE_EVENT);
onCreate(db);
}
}
11-14 14:06:47.938 12123-12123/com.example.myacademicdiary E/SQLiteLog﹕ (1) table event has no column named date
11-14 14:06:47.938 12123-12123/com.example.myacademicdiary E/SQLiteDatabase﹕ Error inserting date= name= description=
android.database.sqlite.SQLiteException: table event has no column named date (code 1): , while compiling: INSERT INTO event(date,name,description) VALUES (?,?,?)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469)
at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1341)
at com.example.myacademicdiaryfyp.event.SQLControler.insertEvent(SQLControler.java:34)
at com.example.myacademicdiaryfyp.event.AddEvent.onClick(AddEvent.java:44)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
答案 0 :(得分:0)
android.database.sqlite.SQLiteException: table event has no column named date (code 1): , while compiling: INSERT INTO event(date,name,description) VALUES (?,?,?)
上述错误告诉我,表date
中没有名为event
的列。很可能您稍后添加了新列date
。
您现在有两个选择来解决此问题。
更改表结构后立即增加数据库版本。
static final int DB_VERSION = 1;