开发者

Android query using extras in the where statement

I having trouble with my database i was wondering how would i be able to connect two variables in a sql query. Example i have a bus schedule that has two tables and im trying to use two put extras to query the results i want but im not sure if im able to use two extras in the where statement to replace the '?' with. I get no errors when i do it but nothing displays but when i take away one of the extras it works but doesnt display the right information that i want. Could someone explain why this wont work if i cant use two '?' at once or if im doing something wrong.

enter code here   



     idDay = getIntent().getStringExtra("Day_ID");
        idNum = getIntent().getIntExtra("BUS_ID", 0);


        Cursor cursor = db.rawQuery
        (

         "SELECT A2._id, A2.dayOfWeek, A2.direction " +
         "FROM TimeTable A2 " + 
//         "WHERE A2._id = ? " +
//         "WHERE A2.dayOfWeek = ? " +
         "WHERE (A2._id 开发者_如何转开发= ?) AND (A2.dayOfWeek = ?) " +
         "GROUP BY A2.direction", 

//       new String[]{""+idNum});        


        new String[]{""+idNum+idDay});     
//         new String[]{""+idNum});        


If you use 2 selection args in your query then you need 2 values in the array:

  new String[] { Integer.toString(idNum), Integer.toString(idDay) }

It doesn't matter where you get the values from.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜