gpt4 book ai didi

java - 如何在 Sqlite 中搜索字符串值?

转载 作者:行者123 更新时间:2023-11-29 04:39:38 25 4
gpt4 key购买 nike

我正在做一个项目,我对sqlite了解甚少。我正在开发用于从 sqlite 本地数据库中搜索名称的 android 应用程序。我想从 editText 框中获取文本(名称),然后在 sqlite 中进行查询。我发现了如何从 editText 框中抓取文本 -

EditText txtname = (EditText)findViewById(R.id.name);
String name = txtname.getText().toString();

根据我的研究,我发现这就是您在 sqlite 中进行查询的方式 -

SELECT * FROM Customers
WHERE City LIKE '%XXXX%';

因为,我不知道用户会在 editText 框中搜索什么。

如何查询用户在 editText 框中输入到 sqlite 数据库。

谢谢

最佳答案

我不确定你在问什么,但我猜这是如何将 name 传递给查询。

例如,使用带有选择参数的 SQLiteDatabase.query()

db.query("Customers", null, "City LIKE ?", new String[] { "%" + name + "%" }, null, null, null);

关于java - 如何在 Sqlite 中搜索字符串值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39760384/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com