以下是我使用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\" ;";
它完美无缺。那么如何编写一个可以动态替换列值的查询呢?
答案 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 + "'";