有人可以帮忙SQLite database
吗android
?
首先,我从这里开始使用教程。它在我的应用程序中运行良好,但是当我添加新列并将database
版本更改为“2”时,应用程序停止并且在文件资源管理器中,没有database
找到。任何人都可以说明问题所在和解决方案。
编辑:这是我的一些更改.. 这是我的 FirstClass.java
// Database creation SQL statement
private static final String DATABASE_CREATE = "create table "
+ TABLE_TODO
+ "("
+ COLUMN_ID + " integer primary key autoincrement, "
+ COLUMN_CATEGORY + " text not null, "
+ COLUMN_SUMMARY + " text not null,"
+ COLUMN_DESCRIPTION
+ " text not null"
+ COLUMN_DATE + "date not null " //i have added the date column
+ ");";
public static void onCreate(SQLiteDatabase database) {
database.execSQL(DATABASE_CREATE);
}
public static void onUpgrade(SQLiteDatabase database, int oldVersion,
int newVersion) {
Log.w(FirstClass.class.getName(), "Upgrading database from version "
+ oldVersion + " to " + newVersion
+ ", which will destroy all old data");
database.execSQL("DROP TABLE IF EXISTS " + TABLE_TODO);
// database.execSQL("INSERT INTO "+TABLE_TODO+" VALUES (null, datetime()) ");
onCreate(database);
}
这是我的 TodoDatabaseHelper.java
private static final String DATABASE_NAME = "todotable2.db";
private static final int DATABASE_VERSION = 2;
public TodoDatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
// Method is called during creation of the database
@Override
public void onCreate(SQLiteDatabase database) {
FirstClass.onCreate(database);
}
// Method is called during an upgrade of the database,
// e.g. if you increase the database version
@Override
public void onUpgrade(SQLiteDatabase database, int oldVersion,
int newVersion) {
FirstClass.onUpgrade(database, oldVersion, newVersion);
}