查询是否正确?在sqlite中插入数据后我没有得到结果吗?

问题描述 投票:-1回答:1

未在结果集中获取数据

这里是代码

public boolean isExist(String question_id, String selected_option, String session_id) {
        db = this.getReadableDatabase();

        Cursor cur = db.rawQuery("SELECT * FROM " + TABLE_TEST_START + " WHERE question_id_test_start = '" +question_id+  "' AND selected_option_test_start = '"+selected_option+"' AND test_start_id = '"+session_id+"'", null);
        boolean exist = (cur.getCount() > 0);
        Log.d("DATA PRESENT ","DATA CHECK"+exist);
        cur.close();
        db.close();
        return exist;

    }
android android-sqlite
1个回答
0
投票

尝试下面的代码,希望可以解决您的问题。

 public Cursor isExist(String question_id,String selected_option,String session_id) {
    SQLiteDatabase db = this.getWritableDatabase();
    return db.rawQuery("SELECT * FROM " +
                    TABLE_TEST_START + " WHERE " +
                    question_id_test_start + "=? AND " +
                    selected_option_test_start + "=? AND " +
                    test_start_id + "=? ",
            new String[] {question_id,selected_option,session_id}
    );
}

获得游标值后,您可以检查其是否存在

© www.soinside.com 2019 - 2024. All rights reserved.