如果我使用DriverManager.getConnection()
和DataSource.getConnection()
獲得連接對象,那麼在這些對象上調用.close()
時,它們在行爲上的差異如何?連接行爲 - DriverManager.getConnection()和DataSource.getConnection()
之前.close()
方法調用,我得到了相關的Statement
和ResultSet
對象從這兩個不同的連接。獲取這兩個對象後不久,如果我說connection1.close()
(通過DriverManager.getConnection()
),它將使連接對象無效,並且我不應該/允許訪問相關的Statement和ResultSet對象。如我錯了請糾正我?
第二種情況,現在如果我說connection2.close()
(通過DataSource.getConnection()
),它只是將它返回到池。但連接仍然存在。我能訪問關聯的Statement
和ResultSet
對象嗎?
在我的應用程序中,即使關閉了我的Connection對象,我也能夠訪問我的ResultSet對象。因此,按照您的說明,Websphere未能實現此目標? – Sriram
這取決於您的訪問意味着什麼。 ResultSet對象仍然存在,但不應該能夠使用ResultSet,因爲在關閉邏輯連接時它應該已經關閉。 –
如果這是WebSphere的不正確實現:這取決於您將什麼用作Websphere的'DataSource'的'ConnectionPoolDataSource'。我描述的行爲應該由'PooledConnection'實現來強制執行。 –