根据提供的条件从 sqlite 获取数据到 edittext

发布于 2024-12-04 10:20:12 字数 495 浏览 3 评论 0原文

我正在开发一个 Android 项目,在该项目中我遇到了一个问题。我需要根据提供的条件从 SQLite db 获取数据。

准确地说,我的意思是说我需要从 SQLite 获取数据,我在其中提供在 EditText 中返回值的显示条件。
比如:

SELECT SPECIALCHARCTER FROM <TABLENAME> WHERE POSITION = "0"; 

我需要一个好的链接来研究这个过程。任何人都可以帮我解决问题吗?

您可以查看DBHelper.java类的示例代码。

我会很高兴看到朋友们的回复并帮助我解决这个问题。

谢谢&问候,

拉加夫

I am working on an Android project where I am struck with a issue. I need to fetch data from SQLite db based on condition provided.

In precise I mean to say I need to get the data from SQLite where I provide condition an display that returned value in EditText.
Like:

SELECT SPECIALCHARCTER FROM <TABLENAME> WHERE POSITION = "0"; 

I need a good link to study this process. Can anyone please help me in issue.

You can check out sample code of DBHelper.java class.

I shall be very happy to see reply from u friends and help me in solving this issue.

Thanks & Regards,

Raghav

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

七七 2024-12-11 10:20:12

尝试按以下方式选择语句,

SELECT * FROM  Contact where position LIKE '%"+0+"%'"

这可能会对您有所帮助

Try select statement in the following way

SELECT * FROM  Contact where position LIKE '%"+0+"%'"

this may helps you

绮筵 2024-12-11 10:20:12

抱歉,您粘贴的代码很混乱,因为它的格式不好并且充满了注释掉的代码。很难看到任何东西。

我看到的是这段代码:

EditText result=(EditText)findViewById(R.id.input);
Cursor c = db.rawQuery("SELECT SPECIALCHARCTER FROM " + TABLE + " where POSITION = 0", null);
int A = c.getColumnIndex("POSITION");
String strRet;
strRet = c.getString(A);
results.setText("" + strRet);
c.moveToNext();

这将因多种原因而失败:

  1. 在访问它之前,您的光标 c 永远不会移动到第一个位置。因此它总是会失败
  2. 在方法末尾调用 c.moveToNext() 是没有意义的
  3. 你的变量结果永远不会初始化

我的建议:从此类中删除每个 UI 元素并开始阅读 Pratik 在他的答案中提供的一些链接。

Sorry but you code pasted is a mess as it is not good formatted and filled with code that is commented out. Hard to see anything.

What I saw was this code:

EditText result=(EditText)findViewById(R.id.input);
Cursor c = db.rawQuery("SELECT SPECIALCHARCTER FROM " + TABLE + " where POSITION = 0", null);
int A = c.getColumnIndex("POSITION");
String strRet;
strRet = c.getString(A);
results.setText("" + strRet);
c.moveToNext();

This will fail for multiple reasons:

  1. Your cursor c is never moved to the first place before you access it. So it will always fail
  2. Calling c.moveToNext() at the end of the method is senseless
  3. Your variable results is never initialized

My advice: Remove every UI element from this class and start reading some links Pratik provided in his answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文