データベースのテーブルから一部のデータを照会するためにselectステートメントを使用しようとしています。 私が入力すると=?私は、%LIKE を使用する場合クエリが成功しますが、%ではなく、私はlogcatでこのエラーました:?SQLite:LIKE '%?%' with rawQueryを使用して選択
FATAL EXCEPTION: main
Process: com.example.ahmed.bus_time_djerba4, PID: 4178
java.lang.IllegalArgumentException: Cannot bind argument at index 2 because the index is out of range. The statement has 0 parameters.
をして、このデータベースを呼び出す私Methodeのです:
public String QuerySQL(String DepartStation,String Destination){
String result="";
SQLiteDatabase db=this.getReadableDatabase();
Cursor c=db.rawQuery("select distinct * from "+TABLE_Name+" where "+Col_3+" LIKE '%?%' and "+Col_4+" LIKE '%?%'", new String[]{DepartStation,Destination});
if(c.getCount()==0) {result="Data not found";c.close();}
else {
while (c.moveToNext()) {
//affichage des lignes
int ligne = c.getInt(1);
String Station = c.getString(2);
String Dest = c.getString(3);
String hours = c.getString(4);
result += "\n" + ligne + "|" + Station + "-" + Dest + " " + hours;
}
c.close();
}
return result;
}
あるもの問題?してください
私は推測する問題は、+ TABLE_NAME +「から明確な*を選択する 『とある』 ...明確な*?それはする 変更 『私は=?ではなくLIKEの使用時にいや、それは動作しますから...』 – Santosh
選択* '%?%' –
とにかく文字列の連結を使用しないでください。 –