Sqlite数据库检索多条数据

发布于 2024-12-23 13:52:32 字数 521 浏览 2 评论 0原文

在 sqLite 中,我从活动中将 3 个值插入到数据库的表中。 我需要从数据库、另一个活动中检索这 3 个值...可以从表中检索第一个值...我无法检索其余 2 个值...如何定义游标对象来执行以下操作相同的???

        myDB = MyService.this.openOrCreateDatabase("antitheft", MODE_PRIVATE, null);
        Cursor cursor1 = myDB.query("SimSerial", null, null, null, null, null, null);
        cursor1.moveToLast();
        String ss1 = cursor1.getString(cursor1.getColumnIndex("simno"));
        cursor2.moveToFirst();
        String num1 = cursor2.getString(cursor2.getColumnIndex("secure"));

In sqLite,i have 3 values inserted in a table in my database ,from an activity.
I need to reteive those 3 values from the database,from another activity...The retreival of the first value from the table is possible..i cant retreive the remaining 2 values...How can the cursor object be defined to do the same???

        myDB = MyService.this.openOrCreateDatabase("antitheft", MODE_PRIVATE, null);
        Cursor cursor1 = myDB.query("SimSerial", null, null, null, null, null, null);
        cursor1.moveToLast();
        String ss1 = cursor1.getString(cursor1.getColumnIndex("simno"));
        cursor2.moveToFirst();
        String num1 = cursor2.getString(cursor2.getColumnIndex("secure"));

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

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

发布评论

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

评论(2

一个人练习一个人 2024-12-30 13:52:32

您可以编写查询来选择所有记录,然后迭代记录。

Cursor cursor1 = myDB.query("SimSerial", null, null, null, null, null, null);

cursor1.moveToFirst();
while(!cursor1.isAfterLast()){
   cursor1.getString(....);
   cursor1.moveToNext();
}

You can write the query for selecting all the records and then iterate through the records.

Cursor cursor1 = myDB.query("SimSerial", null, null, null, null, null, null);

cursor1.moveToFirst();
while(!cursor1.isAfterLast()){
   cursor1.getString(....);
   cursor1.moveToNext();
}
温柔少女心 2024-12-30 13:52:32

您需要迭代游标。为此,您可以使用以下示例。

    Cursor cur = myDB.query("SimSerial", null, null, null, null, null, null);
    cur.moveToFirst();
    while (cur.isAfterLast() == false) {
        String str = cur.getString(1);
        cur.moveToNext();
    }
    cur.close();

You need to iterate cursor. For that you can use following example.

    Cursor cur = myDB.query("SimSerial", null, null, null, null, null, null);
    cur.moveToFirst();
    while (cur.isAfterLast() == false) {
        String str = cur.getString(1);
        cur.moveToNext();
    }
    cur.close();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文