所以我一直在尝试使用该getData()方法进行查询,并且每当我运行调试时,我都可以看到它与该dbHelper.getWritableDatabase()行一起崩溃。
我以为我是在onCreate()方法中创建数据库,所以我不确定发生了什么。
我的代码在下面。我将不胜感激任何帮助!
public String getData(int firstSelection, int secondSelection, int thirdSelection,
int fourthSelection, int fifthSelection)
{
SQLiteDatabase db = dbHelper.getWritableDatabase();
String firstSelectionStr, secondSelectionStr, thirdSelectionStr, fourthSelectionStr, fifthSelectionStr;
firstSelectionStr = Integer.toString(firstSelection);
secondSelectionStr = Integer.toString(secondSelection);
thirdSelectionStr = Integer.toString(thirdSelection);
fourthSelectionStr = Integer.toString(fourthSelection);
fifthSelectionStr = Integer.toString(fifthSelection);
String[] columns = {DBHelper.UID,DBHelper.CNAME};
String selectQuery = "SELECT " + DBHelper.CNAME + " FROM "+ "CraftsAppDatabase" + " WHERE First_Attribute=? "
+ " AND Second_Attribute=? " + " AND Third_Attribute=? " + " AND Fourth_Attribute=? "
+ " AND Fifth_Attribute=? ";
Cursor cursor=db.rawQuery(selectQuery, new String[] {firstSelectionStr, secondSelectionStr, thirdSelectionStr,
fourthSelectionStr, fifthSelectionStr});
StringBuilder buffer = new StringBuilder();
// Append every data together
while (cursor.moveToNext())
{
String chosenItem = cursor.getString(cursor.getColumnIndex(DBHelper.CNAME));
buffer.append(chosenItem + "/n");
}
return buffer.toString();
}
撒科打诨
富国沪深
相关分类