有關連線池的疑惑。
Here is an example of properly written code to use a db connection obtained from a connection pool:
Connection conn = null;
Statement stmt = null; // Or PreparedStatement if needed
ResultSet rs = null;
try {
conn = ... get connection from connection pool ...
stmt = conn.createStatement("select ...");
rs = stmt.executeQuery();
... iterate through the result set ...
rs.close();
rs = null;
stmt.close();
stmt = null;
conn.close(); // Return to connection pool
conn = null; // Make sure we don't close it twice
} catch (SQLException e) {
... deal with errors ...
} finally {
// Always make sure result sets and statements are closed,
// and the connection is returned to the pool
if (rs != null) {
try { rs.close(); } catch (SQLException e) { ; }
rs = null;
}
if (stmt != null) {
try { stmt.close(); } catch (SQLException e) { ; }
stmt = null;
}
if (conn != null) {
try { conn.close(); } catch (SQLException e) { ; }
conn = null;
}
}
以上例子引自:http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-examples-howto.htmlDatabase%20Connection%20Pool%20(DBCP)%20Configurations
我的問題是: conn.close(); // Return to connection pool 這一句,這個connection已經關閉了,怎麼會返回連線池呢?
謝謝!
Connection conn = null;
Statement stmt = null; // Or PreparedStatement if needed
ResultSet rs = null;
try {
conn = ... get connection from connection pool ...
stmt = conn.createStatement("select ...");
rs = stmt.executeQuery();
... iterate through the result set ...
rs.close();
rs = null;
stmt.close();
stmt = null;
conn.close(); // Return to connection pool
conn = null; // Make sure we don't close it twice
} catch (SQLException e) {
... deal with errors ...
} finally {
// Always make sure result sets and statements are closed,
// and the connection is returned to the pool
if (rs != null) {
try { rs.close(); } catch (SQLException e) { ; }
rs = null;
}
if (stmt != null) {
try { stmt.close(); } catch (SQLException e) { ; }
stmt = null;
}
if (conn != null) {
try { conn.close(); } catch (SQLException e) { ; }
conn = null;
}
}
以上例子引自:http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-examples-howto.htmlDatabase%20Connection%20Pool%20(DBCP)%20Configurations
我的問題是: conn.close(); // Return to connection pool 這一句,這個connection已經關閉了,怎麼會返回連線池呢?
謝謝!
相關文章
- 關於連線池的問題!
- 連線資料庫的疑惑資料庫
- 關與連線池的配置問題!
- 關於資料庫連線池資料庫
- 連線池
- 資料庫連線池的問題,連線池物件為靜態變數有問題麼資料庫物件變數
- 各位十一好,問一個有關weblogic 8的連線池的問題Web
- Go連線池Go
- HTTP連線池HTTP
- 有關Java Collection API的一個疑惑JavaAPI
- Http持久連線與HttpClient連線池HTTPclient
- 連線池和連線數詳解
- 有關EJB的有態SessionBean和無態SessionBean的疑惑SessionBean
- golang連線MySQL時候的連線池設定GolangMySql
- 關於tomcat資料庫連線池的問題Tomcat資料庫
- Tomcat 的 JDBC 連線池TomcatJDBC
- Proxool 連線池的配置使用
- HikariCP連線池的學習
- ElasticSearch連線池建立Elasticsearch
- 自定義連線池
- golang tcp連線池GolangTCP
- Oracle 連線池配置Oracle
- oracle occi 連線池Oracle
- Resin 配置連線池
- [尋]連線池例子
- proxool連線池 配置
- 連線池 druidUI
- 【Java面試】資料庫連線池有什麼用?它有哪些關鍵引數?Java面試資料庫
- java連線池解決連線中斷Java
- proxool連線池如何使用SSL方式連線?
- 請關掉你的資料庫連線!並且請使用資料庫連線池資料庫
- ServiceStack.Redis的原始碼分析(連線與連線池)Redis原始碼
- Swoole MySQL 連線池的實現MySql
- 資料庫連線池的理解資料庫
- 資料庫連線池的使用資料庫
- WASCE的資料庫連線池資料庫
- (請問)weblogic的連線池Web
- C#中的連線池管理C#