我正在尝试使用通配符元素来搜索我的SQLite表,以查找在特定变量中任何位置具有元素的条目.
public String[] getCheckoutEntry(String title, String ISBN)
{
//Wild card Syntax
String titleWildCard = "%" + title + "%";
String ISBNWildCard = "%" + ISBN + "%";
//Query
String query = "select USER,AUTHOR,DATE,CALL_NUMBER,COUNT from CHECKOUT where TITLE = ? or ISBN = ? ";
String[] selectionArgs = new String[] {titleWildCard, ISBNWildCard};
Cursor cursor = db.rawQuery(query, selectionArgs);
我已经在Stack Overflow上检查了六个答案,并且每个人都建议只在我的变量上附加一个“%”,如上所示.当我尝试上面的代码时,我的程序只是解释了titleWildCard,包括%作为搜索查询,并尝试在表中找到%.
如果我取出“%”,那么程序运行没有问题,只是它只搜索确切的术语.
解决方法:
使用LIKE替换=运算符使%表现得像通配符:
... where TITLE LIKE ? or ISBN LIKE ?
标签:android,sqlite,android-sqlite
来源: https://codeday.me/bug/20190825/1717667.html