我有一个数据库已经包含一个表“LocalLogin”,并且已经正确设置并且可以在没有问题的情况下被查询,正在设置与我的新表“PersonList”一样。然而,当我尝试执行上PersonList查询选择一些价值观,我得到的错误在数据库上执行查询时Android“android.database.sqlite.SQLiteException:没有这样的表”错误
android.database.sqlite.SQLiteException: no such table: PersonList: , while compiling: SELECT ...
它给我的表从来没有创建的想法,虽然我的onCreate方法执行创建查询我的SQLiteOpenHelper类。与LocalLogin具有相同的数据库名称可能存在的问题?
下面是相关代码:
数据库适配器类
public class GoingOutPersonListDbAdapter {
private static final String DATABASE_NAME = "GoingOutData";
private static final String DATABASE_TABLE_PERSONLIST = "PersonList";
private static final int DATABASE_VERSION = 1;
public static final String PERSONLIST_ID = "PersonList_id";
public static final String PERSONLIST_LOGIN = "Login";
public static final String PERSONLIST_PASSWORD = "Password";
private static final String TAG = "Debugstring";
private PersonListDatabaseHelper mPersonListDbHelper;
private SQLiteDatabase mDb;
private static final String DATABASE_CREATE =
"CREATE Table " + DATABASE_TABLE_PERSONLIST+ " ("
+ PERSONLIST_ID + " integer PRIMARY KEY Autoincrement, "
+ PERSONLIST_LOGIN + " text NOT NULL,"
+ PERSONLIST_PASSWORD + " text NOT NULL);";
private final Context mCtx;
private static class PersonListDatabaseHelper extends SQLiteOpenHelper {
PersonListDatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
Log.d(TAG,DATABASE_CREATE);
db.execSQL(DATABASE_CREATE);
}
}
public GoingOutPersonListDbAdapter(Context ctx) {
this.mCtx = ctx;
}
public GoingOutPersonListDbAdapter open() throws SQLException {
mPersonListDbHelper = new PersonListDatabaseHelper(mCtx);
mDb = mPersonListDbHelper.getWritableDatabase();
return this;
}
public Cursor searchPerson(String searchString) {
return mDb.query(DATABASE_TABLE_PERSONLIST, new String[] {PERSONLIST_ID, PERSONLIST_LOGIN, PERSONLIST_PASSWORD}, searchString, null, null, null, null);
}
}
在我的活动类:
private GoingOutPersonListDbAdapter mPersonListDbHelper;
...
mPersonListDbHelper = new GoingOutPersonListDbAdapter(this);
mPersonListDbHelper.open();
...
//loginEditText is properly set
Cursor personList = mPersonListDbHelper.searchPerson(GoingOutPersonListDbAdapter.PERSONLIST_LOGIN + " = '" + loginEditText + "'");
startManagingCursor(personList);
我添加 “\t \t @Override \t \t公共无效onUpgrade(SQLiteDatabase分贝,INT oldVersion,INT NEWVERSION){ \t \t \t db.execSQL(DATABASE_CREATE); \t \t}”,改变了数据库的版本为2,但我仍然有相同的错误 – 2012-04-09 20:31:36
工程就像一个魅力,我在两个数据库适配器中增加数据库版本,我显然不应该这样做 – 2012-04-09 20:58:30
适合我 – 2012-07-12 10:44:10