由于CharSequence的值,我的sqlite查询出错。在这个值中,我有单引号(人物),但运行不正常。查询运行正确,双倍时间单引号(人物'' s)。
并且代码错误如下所示
07-27 14:48:32.042: E/SQLiteLog(28325): (1) near "s": syntax error
07-27 14:48:32.052: E/AndroidRuntime(28325): FATAL EXCEPTION: main
07-27 14:48:32.052: E/AndroidRuntime(28325): Process:
com.compare.WorldAtlasPro, PID: 28325 07-27 14:48:32.052:
E/AndroidRuntime(28325): android.database.sqlite.SQLiteException: near
"s": syntax error (code 1): , while compiling: SELECT Name FROM
country_info WHERE Name LIKE '%People's Republic of China%' AND Name
NOT LIKE ''AND Name NOT LIKE '' AND Name NOT LIKE ''AND Name NOT LIKE
'' order by Name ASC
以下是我的代码。
country2.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
ArrayList<String> mArrayList=new ArrayList<String>();
Cursor c=db.rawQuery("SELECT Name FROM country_info WHERE Name LIKE '%"+s+"%' AND" +" Name NOT LIKE'"+country1.getText().toString()+"'AND Name NOT LIKE'"+country3.getText().toString()+"' " +" AND Name NOT LIKE'"+country4.getText().toString()+"'AND Name NOT LIKE'"+country5.getText().toString()+"' " + "order by Name ASC", null);
while(c.moveToNext()){
mArrayList.add(c.getString(0));
}
country2.setAdapter(new CustomAdapter(mCtx,mArrayList));
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void afterTextChanged(Editable s) {
}
});