我想从名为课程,具有属性名称的SQLite表中获取一些数据。Android的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”不存在
你是否在某处遇到异常?究竟是什么问题? –
我忘了添加它,编辑! – wilxjcherokee
它是说没有任何名称为“_id”的列检查您的数据库定义 –