给定以下(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 nameat 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)),但它从未解决问题。我完全不知道为什么它在这里不能像在数据库中那样工作。
1 回答
一只斗牛犬
TA贡献1784条经验 获得超2个赞
还有另一种基于索引的同名方法。
int getInt(int columnIndex) throws SQLException
尝试查看是否有效。正如我从图像中看到的那样,索引为 4(从 1 开始编号列)
player.xp = result.getInt(4);
添加回答
举报
0/150
提交
取消