[英]SQLite query not working with concatenated string
这是我使用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\" ;";
它完美地工作。 那么,如何编写查询以动态替换列值呢?
试试这个会起作用
准确输入
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);
String query = "select * from table where col = \""+value+"\" ";
String query = "select * from table where col ='" +inputWord + "'";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.