Android SQLite rawquery parameters

前端 未结 3 1621
一个人的身影
一个人的身影 2020-12-06 10:03

How can i pass intger to a rawquery in sqlite for android. Here its not taking g and s into query. Please guide.

    int g, s;

    Cursor cur3 = database2         


        
相关标签:
3条回答
  • 2020-12-06 10:46

    Parameter in your query needs to be string so please convert these parameters into string and write your query as follows.

    Use String.valueOf();

    Cursor c = db.rawQuery(SELECT max(UnixTimeStamp) 
                           FROM Quote 
                           WHERE EmoticonID ='"+d+"' AND SubCategoryID ='"+ s +"'");
    

    Thanks

    0 讨论(0)
  • 2020-12-06 10:51

    All parameter places should be designated with ?. The parameters to the query are always string nontheless, so nothing special about the integers. This should work for you:

    Cursor cur3 = database2.rawQuery("select max(UnixTimeStamp) from Quote where EmoticonID=? and SubCategoryID=?" ,new String [] {String.valueOf(g),String.valueOf(s)});
    
    0 讨论(0)
  • 2020-12-06 10:59
    Cursor cur3 = database2.rawQuery("select max(UnixTimeStamp) from Quote where EmoticonID="
                                     + g + " and SubCategoryID = " + s + " ");
    
    0 讨论(0)
提交回复
热议问题