0
每當我嘗試獲取ResultSet時,都會收到此錯誤。我在網上看了很長時間,並且有很多poeple和我一樣得到同樣的問題,但是他們的問題是他們使用PreparedStatement進行多個查詢。ResultSet關閉錯誤後即使PreparedStatement僅使用一次也不允許操作
正如你在下面的代碼中看到的,我只使用了PreparedStatement一次。
getSQLConnection()方法返回一個全新的Connection。 將引發錯誤就行了:結果集RS = ps.executeQuery()
try (Connection connection = getSQLConnection();
PreparedStatement ps = connection.prepareStatement(qry);
ResultSet rs = ps.executeQuery()) {
return rs;
} catch (SQLException ex) {
plugin.get().getLogger().log(Level.SEVERE, "Couldn't execute SQL statement: ", ex);
}
我已經使用SQL數據庫之前也從來沒有這樣做過。我很困惑。希望你們能幫助我!