我有一個問題,當我嘗試編譯我的android apliccation。錯誤SQLite沒有這樣的列(代碼1),同時編譯
如果我添加一列(日期星)到數據庫已經出現了一個錯誤:
android.database.sqlite.SQLiteException:沒有這樣的柱:出生日期(碼1):在編譯:SELECT _id,任務,地點,重要性,出生日期FROM todolist的ORDER BY重要性
這是類日數據庫
public class DataBaseHelper {
private Context mCtx = null;
private DataBaseHelperInternal mDbHelper = null;
private SQLiteDatabase mDb = null;
private static final String DATABASE_NAME = "TODOLIST";
private static final int DATABASE_VERSION = 200;
// tabla y campos
private static final String DATABASE_TABLE_TODOLIST = "todolist";
public static final String SL_ID = "_id";
public static final String SL_ITEM = "task";
public static final String SL_PLACE = "place";
public static final String SL_DATE = "fecha";
public static final String SL_IMPORTANCE = "importance";
public static final String SL_DESCRIPTION = "description";
// SQL de creación de la tabla
private static final String DATABASE_CREATE_TODOLIST =
"create table " + DATABASE_TABLE_TODOLIST
+" (" + SL_ID + " integer primary key,"
+ SL_ITEM + " text not null,"
+ SL_PLACE + " text not null,"
+ SL_IMPORTANCE + " integer not null,"
+ SL_DESCRIPTION + " text,"
+ SL_DATE + " text"
+ ");";
//constructor
public DataBaseHelper(Context ctx) {
this.mCtx = ctx;
}
//clase privada para control de la SQLite
private static class DataBaseHelperInternal extends SQLiteOpenHelper {
public DataBaseHelperInternal(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
createTables(db);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
deleteTables(db);
createTables(db);
}
private void createTables(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE_TODOLIST);
}
private void deleteTables(SQLiteDatabase db) {
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE_TODOLIST);
}
}
public DataBaseHelper open() throws SQLException {
mDbHelper = new DataBaseHelperInternal(mCtx);
mDb = mDbHelper.getWritableDatabase();
return this;
}
public void close() {
mDbHelper.close();
}
//obtener todos los elementos
public Cursor getItems() {
return mDb.query(DATABASE_TABLE_TODOLIST, new String[] {SL_ID,SL_ITEM,SL_PLACE,SL_IMPORTANCE,SL_DATE}, null, null, null, null, SL_IMPORTANCE);
}
//crear elemento
public long insertItem(String item, String date, String place, String description, int importance){
ContentValues initialValues = new ContentValues();
initialValues.put(SL_IMPORTANCE, importance);
initialValues.put(SL_ITEM, item);
initialValues.put(SL_DATE, date);
initialValues.put(SL_PLACE, place);
initialValues.put(SL_DESCRIPTION, description);
return mDb.insert(DATABASE_TABLE_TODOLIST, null, initialValues);
}
public Cursor getItem(int itemId){
return mDb.rawQuery(" select "+ SL_ITEM+","+ SL_DATE+","+ SL_PLACE+","+ SL_DESCRIPTION+","+SL_IMPORTANCE + "," + SL_ID + " from " + DATABASE_TABLE_TODOLIST + " where " + SL_ID + "= ?",new String[]{Integer.toString(itemId)});
}
當您嘗試從表中
收集數據出現的錯誤謝謝大家!
非常感謝,現在它工作! –