获取玩家位置的SQL查询方法

huangapple 未分类评论46阅读模式
英文:

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(&#39;&lt;columnName&gt;&#39;) instead of rs.getRow()

huangapple
  • 本文由 发表于 2020年4月8日 19:23:43
  • 转载请务必保留本文链接:https://java.coder-hub.com/61099516.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定