Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android SQLite数据库中的多个条目_Android_Sqlite_Android Sqlite - Fatal编程技术网

Android SQLite数据库中的多个条目

Android SQLite数据库中的多个条目,android,sqlite,android-sqlite,Android,Sqlite,Android Sqlite,当我在数据库中输入字符串时,我能够检索它。但是如果我打开数据库,再次将另一个字符串放入数据库并关闭它,则条目不存在 entry.open(); entry.putChampion1IntoDb(jsonString); entry.close(); entry.open(); entry.putChampion2IntoDb(jsonString2);

当我在数据库中输入字符串时,我能够检索它。但是如果我打开数据库,再次将另一个字符串放入数据库并关闭它,则条目不存在

            entry.open();
            entry.putChampion1IntoDb(jsonString);
            entry.close();



            entry.open();
            entry.putChampion2IntoDb(jsonString2);
            entry.close();

    public long putChampion1IntoDb(String json) {
        ContentValues cv = new ContentValues();
        cv.put(KEY_CHAMPION_1, json);

        return mDatabase.insert(DATABASE_TABLE, null, cv);
    }

    public long putChampion2IntoDb(String json) {
        ContentValues cv = new ContentValues();
        cv.put(KEY_CHAMPION_2, json);

        return mDatabase.insert(DATABASE_TABLE, null, cv);
}
然后,当我调用DB类检索数据时,字符串返回null

public JSONObject getChampions2() throws JSONException {
        Cursor c = mDatabase.query(DATABASE_TABLE, mColumns, null, null, null, null, null);
        c.moveToFirst();
        String jsonFeed = c.getString(c.getColumnIndex(KEY_CHAMPION_2));
        JSONObject json = new JSONObject(jsonFeed);
        return json;
}
也许我用c.moveToFirst()在数据库中导航时出错了

我将有大约5列和1行。(至少在我的脑海里我是这样想象的)


|冠军1 |冠军2 |冠军3 |冠军4 |冠军5|

第一次使用I.open()和.putChampionToDB(字符串)时,关联的键是第一列。 光标与行关联是否正确?所以,c.moveToFirst()移动到存储我所有信息的第一行,对吗


谢谢你

我认为您不了解数据库是如何工作的。每次调用insert时,都会插入新行。你真的有这样的数据: |冠军1 |冠军2 |冠军3 |冠军4 |冠军5|

|一些数据|空|空|空|空|

|null | somedata | null | null | null|

等等。这就是为什么,当您检索第一行并尝试获取KYY_CHAMPION2时,它是空的

我想,你们真的需要做一张桌子

|_id |冠军|

并将数据的每一部分存储在单独的行中。然后您可以轻松地迭代并抛出它们


如果仍然希望将数据存储在一行中,则需要在第一次之后调用db.update(),而不是db.insert()。但在调用update时,必须确定要更新的行。如果您没有某些列作为主键,则可能会出现问题。

谢谢!有道理。所以,| id |冠军|钥匙| 1 | | id |冠军|钥匙| 2 |。。。。等等。。。好吧,很难在这条评论中划出一行