"select * from bus where bus_route like ? and bus_route like ? order by bus_id asc limit ?,?",
newString[]{
"%"+String.valueOf(busStartplace)+"%",
"%"+String.valueOf(busArrayplace)+"%",
String.valueOf(offset),
String.valueOf(maxResult)});
Bus bus =null;
List<Bus> busList =newArrayList<Bus>();
while(cursor.moveToNext()){
int busId =cursor.getInt(cursor.getColumnIndex("bus_id"));
String busCard =cursor
.getString(cursor.getColumnIndex("bus_card"));
String busTeam =cursor
.getString(cursor.getColumnIndex("bus_team"));
String Startplace =cursor.getString(cursor
.getColumnIndex("bus_startplace"));
String Arrayplace =cursor.getString(cursor
.getColumnIndex("bus_arrayplace"));
String busRoute =cursor.getString(cursor
.getColumnIndex("bus_route"));
bus =new Bus(busId, busCard, busTeam, Startplace,
Arrayplace, busRoute);
busList.add(bus);
}
cursor.close();
return busList;
}
需要注意的问题:
①模糊查询部分,当使用like进行模糊查询时,又使用到?占位符时,可以使用以下方式进行查询 错误的方法是:"select * from bus where bus_route like '%?%' and bus_route like '%?%' order by bus_id asc limit ?,?"
Cursorcursor= sqldb
.rawQuery(
"select * from bus where bus_route like ? and bus_route like ? order by bus_id asc limit ?,?",