英文:
Method to get the placement of a player with SQL Query
问题
我想创建一个BuildFFA插件。这个插件包含一个统计系统。我想创建一个方法来计算你的名次。
public static int ranking(UUID uuid) {
try (PreparedStatement ps = MySQL.getConnection().prepareStatement("SELECT *, ROW_NUMBER() OVER (ORDER BY Kills DESC) pos FROM kills WHERE UUID = ?")){
ps.setString(1, uuid.toString());
ResultSet rs = ps.executeQuery();
if(rs.next()) {
return rs.getRow();
}
} catch (SQLException e) {
e.printStackTrace();
}
return -1;
}
问题:
如果数据库中包含该玩家,它总是返回1。
我该如何修复它?
英文:
I want to create a BuildFFA plugin. This plugin contains a Statistic-System. I want to create a method which calculate your placement.
public static int ranking(UUID uuid) {
try (PreparedStatement ps = MySQL.getConnection().prepareStatement("SELECT *, ROW_NUMBER() OVER (ORDER BY Kills DESC) pos FROM kills WHERE UUID = ?")){
ps.setString(1, uuid.toString());
ResultSet rs = ps.executeQuery();
if(rs.next()) {
return rs.getRow();
}
} catch (SQLException e) {
e.printStackTrace();
}
return -1;
}
Problem:
If the database contains the player it always return 1.
How can I fix it?
答案1
得分: 0
你需要使用rs.getInt("<columnName>")
,而不是rs.getRow()
。
英文:
You need to use rs.getInt('<columnName>')
instead of rs.getRow()
专注分享java语言的经验与见解,让所有开发者获益!
评论