亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

java中的列名無效,但適用于數據庫

java中的列名無效,但適用于數據庫

拉風的咖菲貓 2022-05-12 18:37:38
給定以下(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);


查看完整回答
反對 回復 2022-05-12
  • 1 回答
  • 0 關注
  • 599 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號