int FROMcountryChooseId=10;
String ToConvert = (EditView)findViewById(R.id.NumberEditView);
String query="SELECT DISTINCT trim(Country.Country) FROM Country,DCI WHER开发者_如何学JAVAE Country.CountryN°= "+FROMcountryChooseId+ " AND Country.Country LIKE "+"'&ToConvert&'"+" AND DCI._ID=Medicaments.DCIN° ORDER BY DRUG ASC LIMIT 1000;";
myDataBase.rawQuery(query, selectionArgs)
Hi i don't know how to make my query recognize wordToConvert as variable that content something and not just a String.
Any idea how to do that??
thanks for helping
You should use SQLiteDatabase.rawQuery to perform proper string substitutions.
sqliteDatabase.rawQuery(
"SELECT DISTINCT trim(Country.Country)
FROM Country,DCI
WHERE Country.CountryN°= ?
AND Country.Country LIKE ?
AND DCI._ID=Medicaments.DCIN°
ORDER BY DRUG ASC
LIMIT 1000",
new String[] {
Integer.toString(FROMcountryChooseId),
"%" + ToConvert + "%"
});
Just place a ?
where your literals go, and set the corresponding value in the string array. Android will properly escape and quote the value, so you do not need to pre-process it in any way.
In this case, a LIKE
expression is just a literal like any other.
Note that semicolons are not needed here, as multiple statements are not supported.
精彩评论