简体   繁体   English

SQLite查询不适用于串联字符串

[英]SQLite query not working with concatenated string

Here is the code of my android app where I use SQLite: 这是我使用SQLite的android应用程序的代码:

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

This gives me no results. 这没有结果。 Whereas if I remove the concatenation, 而如果我删除串联,

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

it works perfectly. 它完美地工作。 So how do I write a query where I can replace the column value dynamically? 那么,如何编写查询以动态替换列值呢?

Try this it will work 试试这个会起作用

for exact input 准确输入

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

for input start from end 从头开始输入

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

for input start from starting point 从起点开始输入

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

for input contains any where in column 输入包含列中的任何位置

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

execute query 执行查询

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM