给定以下(MYSQL-)查询:
SELECT view_match_metric.player_id, discord_id, view_match_metric.name,
view_match_metric.xp AS xpthis, player.xp AS xptotal, ranked, mode, mu, sigma,
IF(team = 'Alpha', goals_alpha > goals_beta, goals_beta > goals_alpha) as won
FROM view_match_metric
LEFT OUTER JOIN kl_idmap ON view_match_metric.player_id = kl_idmap.player_id
LEFT OUTER JOIN kl_trueelo ON view_match_metric.player_id = kl_trueelo.player_id
LEFT OUTER JOIN player ON view_match_metric.player_id = player.player_id
WHERE match_id="169498"
当我在我的数据库程序(Adminer)上执行它时,它返回以下结果:
请注意,它确实包含 xpthis 和 xptotal 的 int(10) 无符号条目
然而在java中这个查询抛出一个
java.sql.SQLException: Invalid column name
at com.sun.rowset.CachedRowSetImpl.getColIdxByName(Unknown Source)
at com.sun.rowset.CachedRowSetImpl.getInt(Unknown Source)
对于 xpthis 和 xptotal 字段。它确实可以在没有获得这些字段的情况下工作。由于 xp 字段在多个表中不明确,我确实使用这些别名来指定它们。
加载数据的代码:
while (result.next()) {
match.mode = result.getString("mode");
match.ranked = result.getBoolean("ranked");
TrueEloPlayerData player = new TrueEloPlayerData();
player.id = result.getLong("player_id");
player.discordID = result.getLong("discord_id");
player.name = result.getString("name");
//exception thrown in next line:
player.xp = result.getInt("xpthis");
player.level = Utility.getLevel(result.getInt("xptotal"));
//some more
match.players.add(player);
}
对于并行处理,通常的 ResultSet 被复制到 CachedRowSet 中:
CachedRowSet res = RowSetProvider.newFactory().createCachedRowSet();
res.populate(resultSet);
我尝试使用 getDouble、getString 获取它们,甚至使用 getObject,尝试直接访问没有别名的字段 (getInt(tablename.xp)),但它从未解决问题。
我完全不知道为什么它在这里不能像在数据库中那样工作。
一只斗牛犬
相关分类