給定以下(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
提交
取消