java.sql.SQLException: Io 異常: Connection reset

來源:互聯網
上載者:User

當資料庫連接池中的串連被建立而長時間不使用的情況下,該串連會自動回收並失效,但用戶端並不知道,在進行資料庫操作時仍然使用的是無效的資料庫連接,這樣,就導致用戶端程式報“ java.sql.SQLException: Io 異常: Connection reset” 或“java.sql.SQLException 關閉的串連”異常。

在配置資料來源後面加上

<property name="validationQuery" value="select * from dual"/>

配置後,用戶端在使用一個無效的串連時會先對該串連進行測試,如果發現該串連已經無效,則重新從串連池擷取有效資料庫連接來使用。

 

在tomcat的context.xml裡面設定資料來源時候可參考:

 <Resource auth="Container"
  driverClassName="oracle.jdbc.OracleDriver"
  type="javax.sql.DataSource"
  url="jdbc:oracle:thin:@11.11.11.45:1521:orcl"
  name="jdbc/login"
  username="login"
  password="login"
  maxActive="15"
  maxIdle="10"
  maxWait="-1"
  minIdle="2"
  removeAbandonedTimeout="5"
  testOnBorrow="true"
  testWhileIdle="true"
  testOnReturn="true"
  removeAbandoned="true"
  logAbandoned="true"
  validationQuery="select 1 from dual"
 /> 
 
 <Resource auth="Container"
  driverClassName="oracle.jdbc.OracleDriver"
  type="javax.sql.DataSource"
  url="jdbc:oracle:thin:@11.11.11.44:1521:orcl"
  name="jdbc/intraweb"
  username="intraweb"
  password="intraweb"
  maxActive="15"
  maxIdle="10"
  maxWait="-1"
  minIdle="2"
  removeAbandonedTimeout="5"
  testOnBorrow="true"
  testWhileIdle="true"
  testOnReturn="true"
  removeAbandoned="true"
  logAbandoned="true"
  validationQuery="select 1 from dual"
 />

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.