0

这是我使用 SQLite 的 android 应用程序的代码:

String wordInQuotes = "\"" + inputWord + "\"";
String query = "select * from table where col = " +wordInQuotes + ";";
Cursor cursor = database.rawQuery(query, null);

这没有给我任何结果。而如果我删除连接,

 String query = "select * from table where col = \"apple\" ;";

它完美地工作。那么如何编写一个可以动态替换列值的查询呢?

4

3 回答 3

2

试试这个它会工作

精确输入

String query = "select * from table where col = '" +inputword + "'";

输入从结尾开始

String query = "select * from table where col = '" +inputword + "%'";

输入从起点开始

String query = "select * from table where col = '%" +inputword + "'";

输入包含列中的任何位置

String query = "select * from table where col = '%" +inputword + "%'";

执行查询

Cursor cursor = database.rawQuery(query, null);
于 2013-06-23T11:57:38.903 回答
1
String query = "select * from table where col = \""+value+"\" ";
于 2013-06-23T11:41:51.750 回答
0
String query = "select * from table where col ='" +inputWord + "'";
于 2013-06-23T11:48:31.407 回答