SQLite Exception no such column when trying to select

前端 未结 5 998
广开言路
广开言路 2020-11-27 20:21

I have the following DB helper class:

public int studentExists(String studid) {
    Cursor dataCount = mDb.rawQuery(\"select count(*) from usertable where \"         


        
5条回答
  •  悲&欢浪女
    2020-11-27 20:55

    I think you got the answer to what's wrong from Antlersoft or p.campbell, to format the query correctly, I would suggest, you do it like this :

    mDb.rawQuery("select count(*) from usertable where " + KEY_STUDID + "=?", studid);
    

    That should (1) solve your problem and (2) protect you from SQL injections

    Also, I am not sure that

    dataCount.getInt(0);
    

    is the best thing to do... you should probably use getColumnIndex to make sure you are getting the right data...

提交回复
热议问题