我在 android 中创建了应用程序,我执行 crud 操作。在应用程序中数据库文件已成功创建,但在创建表期间出错,以下是 Logcat 错误和数据库适配器类。
Logcat 错误
01-17 13:03:59.139: E/SQLiteLog(1036): (1) table timerecordsnew1 has no column named note
01-17 13:03:59.309: E/SQLiteDatabase(1036): Error inserting note=asdfsdfadf
01-17 13:03:59.309: E/SQLiteDatabase(1036): android.database.sqlite.SQLiteException: table timerecordsnew1 has no column named note (code 1): , while compiling: INSERT INTO timerecordsnew1(note) VALUES (?)
01-17 13:03:59.309: E/SQLiteDatabase(1036): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
以下是我的数据库适配器类
public class TimeTrackerAdapter {
private static final int DATABASE_VERSION = 4;
private static final String DATABASE_NAME = "timetrackernew1.db";
//Table
private static final String TABLE_NAME = "timerecordsnew1";
//Table Column Variable
public static final String TIMERECORDS_COLUMN_ID = "id";
public static final String TIMERECORDS_COLUMN_TIME = "time";
public static final String TIMERECORDS_COLUMN_NOTE = "note";
private TimeTrackerOpenHelper openHelper;
private SQLiteDatabase sqlDb;
//Database creation sql statement
private static final String SQL_CREATE_ENTRIES = "CREATE TABLE " +
TABLE_NAME + "(" + TIMERECORDS_COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
TIMERECORDS_COLUMN_TIME + " TEXT " + TIMERECORDS_COLUMN_NOTE + " TEXT);";
public TimeTrackerAdapter(Context context) {
openHelper = new TimeTrackerOpenHelper(context);
sqlDb = openHelper.getWritableDatabase();
}
//to insert data into database
public void saveRecords(String t, String n) {
ContentValues contentValues = new ContentValues();
contentValues.put(TIMERECORDS_COLUMN_NOTE,t);
contentValues.put(TIMERECORDS_COLUMN_NOTE, n);
sqlDb.insert(TABLE_NAME, null, contentValues);
}
//get fetch the all data
public Cursor getAllRecords() {
return sqlDb.rawQuery("select * from " + TABLE_NAME, null);
}
// inner class
private class TimeTrackerOpenHelper extends SQLiteOpenHelper {
public TimeTrackerOpenHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
System.out.println("create statement"+SQL_CREATE_ENTRIES);
try
{
db.execSQL(SQL_CREATE_ENTRIES);
}catch(SQLiteException sql)
{
sql.printStackTrace();
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
}
}
请任何人帮我解决这个错误。
感谢您