Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在sqlite为Android准备的语句中使用%?%_Android_Sqlite - Fatal编程技术网

如何在sqlite为Android准备的语句中使用%?%

如何在sqlite为Android准备的语句中使用%?%,android,sqlite,Android,Sqlite,当前我的查询如下所示 Cursor c = db.query(CONTENT_TABLE, new String[]{"content"}, "content like %?%", new String[]{keyword}, null, null, null); 我要做的是写一个准备好的语句,用%号括起来。这是我的日志 android.database.sqlite.SQLiteException: near "%": syntax error (code 1): , while compi

当前我的查询如下所示

Cursor c = db.query(CONTENT_TABLE, new String[]{"content"}, "content like %?%", new String[]{keyword}, null, null, null);
我要做的是写一个准备好的语句,用%号括起来。这是我的日志

android.database.sqlite.SQLiteException: near "%": syntax error (code 1): , while compiling: SELECT content FROM `const` WHERE content like %?%
如何正确地执行此操作?

我使用

Cursor c = db.query(CONTENT_TABLE, null, "content like ?", new String[]{"%" + keyword + "%"}, null, null, null);

它工作得很好

您需要引用您正在搜索的字符串,以将其与阻止sql注入的SQLDo分开?使用?对于绑定变量,可以防止注入。引用它的原因与Java或C中所需的原因相同——告诉你所比较的是什么,并把它与它所包含的源代码区分开来。你能再清楚一点吗?