SQLite查询不使用连接字符串

时间:2013-06-23 11:40:39

标签: java android string sqlite android-sqlite

以下是我使用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\" ;";

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

3 个答案:

答案 0 :(得分: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);

答案 1 :(得分:1)

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

答案 2 :(得分:0)

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