Mat*_*men 3 sqlite android create-table
我有一个数据库已经包含一个表"LocalLogin",并且设置正确,可以毫无问题地查询,设置方式与我的新表"PersonList"相同.但是,当我尝试在PersonList上执行查询以选择某些值时,我得到错误
android.database.sqlite.SQLiteException: no such table: PersonList: , while compiling: SELECT ...
Run Code Online (Sandbox Code Playgroud)
虽然我在SQLiteOpenHelper类的onCreate方法中执行了创建查询,但它让我觉得该表从未创建过.是否具有与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);
}
Run Code Online (Sandbox Code Playgroud)
}
在我的活动课上:
private GoingOutPersonListDbAdapter mPersonListDbHelper;
...
mPersonListDbHelper = new GoingOutPersonListDbAdapter(this);
mPersonListDbHelper.open();
...
//loginEditText is properly set
Cursor personList = mPersonListDbHelper.searchPerson(GoingOutPersonListDbAdapter.PERSONLIST_LOGIN + " = '" + loginEditText + "'");
startManagingCursor(personList);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4524 次 |
| 最近记录: |