我正在尝试从名为 Course 的 sqlite 表中获取一些数据,其中包含属性名称。
我在这里建表。
private static final String COURSE_ID = "CourseID";
private static final String COURSE_NAME = "Name";
private static final String COURSE_CODE = "CourseCode";
private static final String COURSE_ROWID = "_id";
private static final String COURSE_CREATE =
"create table " +
"Course" + " ( " +
COURSE_ROWID + " integer primary key autoincrement, " +
COURSE_ID + " integer not null,"
+ COURSE_NAME + " text not null, " +
COURSE_CODE + " text not null" + ");";
我尝试使用此功能选择我的数据。
public Cursor getCourseNames() throws SQLException {
String[] values = {COURSE_NAME};
mDb = mDbHelper.getReadableDatabase();
return mDb.query("Course",values, COURSE_ROWID + "=" + "Name", null, null, null, null, null);
}
然后在我的主课中,我像这样执行它。
public void buildCoursetoChapterList(){
Cursor cursor = dbHelper.getCourseNames();
SimpleCursorAdapter adapter = new SimpleCursorAdapter(MainActivity.this, android.R.layout.simple_list_item_1, cursor, null, null);
ListView listView = (ListView) findViewById(R.id.list);
listView.setAdapter(adapter);
}
我只想获取数据并放入列表视图中,知道我做错了什么吗?这似乎是合乎逻辑的Select from Course WHERE _id = "Name"
;
哦嘟嘟我忘记了我的错误... java.lang.IllegalArgumentException:列'_id'不存在