gpt4 book ai didi

java - 比较 SQLite 数据库中的数据 - Android (java)

转载 作者:行者123 更新时间:2023-12-02 00:05:03 26 4
gpt4 key购买 nike

我制作了一个包含 3 列的 SQLite 高分;排名(int)、分数(long)和百分比(int)。我试图从列中提取所有数据,并将它们与用户刚刚获得的分数进行比较,看看他们的新分数是否进入了前 10 名的高分列表。

我希望高分首先按百分比优先,然后通过得分来打破平局。下面是我开始这样做的地方。我走在正确的轨道上吗?我从未在 Java 之外使用过 SQLite,所以这对我来说是全新的。

预先感谢您的帮助。

//Check if new record makes the top 10.
public boolean check(int rank, long score, int percentage) {
//SQL query to get last score/percentage if highscores has 10 records...
long[] scores = new long[9];
int[] percentages = new int[9];
scores = db.execSQL("SELECT " + SCORE + " FROM " + TABLE + ";"); //Error: Type mismatch
percentages = db.execSQL("SELECT " + PERCENTAGE + " FROM " + TABLE + ";"); //Error: Type mismatch
//Algorithms to compare scores and percentages go here...
}

最佳答案

 scores = db.execSQL("SELECT " + SCORE + " FROM " + TABLE + ";");

execSQL 返回 void。

根据 javadoc

Execute a single SQL statement that is NOT a SELECT or any other SQL statement that returns data.

您可能需要使用 query (或)rawQuery进行选择的机制。

关于java - 比较 SQLite 数据库中的数据 - Android (java),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14058520/

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