0

我有一個java程序,在工作好幾個小時後給了我一個錯誤......這些程序用於在我們以前有windows server 2003的服務器上正常工作,現在我們已經升級到帶有更高配置的windows server 2008,新安裝的SQL Server。是否有任何數據庫設置,我失蹤或有任何操作系統設置,我錯過了?這個錯誤是與操作系統還是數據庫有關?

我收到的例外是:

Error::

org.apache.commons.dbcp.SQLNestedException:Cannot create PoolableConnectionFactory, cause: Network error

IOException: No buffer space available (maximum connections reached?): connect

回答

1

我曾經歷過在Windows類似的問題,必須作出註冊表更改。這與套接字以高速打開和關閉的事實相關,這比由操作系統清理更快。

我不記得具體的註冊表設置,但它增加了用戶應用程序可用的數量或套接字連接。

如果我沒記錯,操作系統默認爲5000個連接。

+0

還沒有得到確切的解決方案,但我也認爲它是與套接字有關...註冊表解決方案太冒險,所以雲沒有嘗試它..並沒有得到確切的方式做到這一點。 – 2011-01-25 07:46:45

0

使用不同的數據庫連接池包像C3P0。另外,請檢查其與您的JDBC驅動程序的兼容性。

0

I have a java programs that gives me an error after working fine for a few hours ...

IOException: No buffer space available (maximum connections reached?)

的JDBC代碼很可能在其中已經獲取該連接的tryfinally塊未正確關閉連接。這樣,連接將保持打開,直到數據庫強制超時並關閉它們。超時取決於使用的數據庫配置。顯然,在以前的機器中超時時間相對較短,而在新機器中超時時間相對較長。當數據庫用完可用連接,因爲你的應用程序永遠不會關閉它們,那麼你將會得到這樣的異常。

下面的代碼示例說明正常(基本)JDBC資源處理成語(注碼流和代碼註釋):

public List<Entity> list() throws SQLException { 
    // Declare resources. 
    Connection connection = null; 
    PreparedStatement statement = null; 
    ResultSet resultSet = null; 
    List<Entity> entities = new ArrayList<Entity>(); 

    try { 
     // Acquire resources. 
     connection = database.getConnection(); 
     statement = connection.prepareStatement("SELECT id, name, value FROM entity"); 
     resultSet = statement.executeQuery(); 

     // Gather data. 
     while (resultSet.next()) { 
      Entity entity = new Entity(); 
      entity.setId(resultSet.getLong("id")); 
      entity.setName(resultSet.getString("name")); 
      entity.setValue(resultSet.getInteger("value")); 
      entities.add(entity); 
     } 
    } finally { 
     // Close resources in reversed order. 
     if (resultSet != null) try { resultSet.close(); } catch (SQLException logOrIgnore) {} 
     if (statement != null) try { statement.close(); } catch (SQLException logOrIgnore) {} 
     if (connection != null) try { connection.close(); } catch (SQLException logOrIgnore) {} 
    } 

    // Return data. 
    return entities; 
} 
相關問題