我有两张表,分别是Subject和chapter。我需要通过传递Subject_id来显示chapter_name。我的问题是如何做到这一点?当我传递值 id 不返回任何东西。
请给点提示。
这是我的代码供参考。
public List<ObjectiveWiseQuestion> getAllChapter(long subId)
{
List<ObjectiveWiseQuestion>LocwiseProfileList=new ArrayList<ObjectiveWiseQuestion>();
String selectQuery=("select chapterName from chapter where subject_id ='"+ subId +"'");
db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst())
{
do {
ObjectiveWiseQuestion owq= new ObjectiveWiseQuestion();
owq.setChapterName(cursor.getString(2));
LocwiseProfileList.add(owq);
} while(cursor.moveToNext());
db.close();
}
return LocwiseProfileList;
}
它还显示了非法状态异常。