cx_Oracle.SessionPool 連線池
官網地址:
The example below shows how to connect to Oracle Database using a connection pool:
# Create the session pool
pool = cx_Oracle.SessionPool("hr", userpwd,
"dbhost.example.com/orclpdb1", min=2, max=5, increment=1, encoding="UTF-8")
# Acquire a connection from the pool
connection = pool.acquire()
# Use the pooled connection
cursor = connection.cursor()
for result in cursor.execute("select * from mytab"):
print(result)
# Release the connection to the pool
pool.release(connection)
# Close the pool
pool.close()
Applications that are using connections concurrently in multiple threads should set the threaded parameter to True when creating a connection pool:
# Create the session pool
pool = cx_Oracle.SessionPool("hr", userpwd, "dbhost.example.com/orclpdb1",
min=2, max=5, increment=1, threaded=True, encoding="UTF-8")
Python Callback
If the sessionCallback parameter is a Python procedure, it will be called whenever acquire() will return a newly created database connection that has not been used before. It is also called when connection tagging is being used and the requested tag is not identical to the tag in the connection returned by the pool.
An example is:
# Set the NLS_DATE_FORMAT for a session
def initSession(connection, requestedTag):
cursor = connection.cursor()
cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI'")
# Create the pool with session callback defined
pool = cx_Oracle.SessionPool("hr", userpwd, "orclpdb1",
sessionCallback=initSession, encoding="UTF-8")
# Acquire a connection from the pool (will always have the new date format)
connection = pool.acquire()
If needed, the initSession() procedure is called internally before acquire() returns. It will not be called when previously used connections are returned from the pool. This means that the ALTER SESSION does not need to be executed after every acquire() call. This improves performance and scalability.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31560527/viewspace-2673870/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 連線池
- HTTP連線池HTTP
- django連線池Django
- Http持久連線與HttpClient連線池HTTPclient
- 連線池和連線數詳解
- 自定義連線池
- ElasticSearch連線池建立Elasticsearch
- 資料庫連線池-Druid資料庫連線池原始碼解析資料庫UI原始碼
- Golang SQL連線池梳理GolangSQL
- Tomcat 的 JDBC 連線池TomcatJDBC
- go 語言連線池Go
- 《四 資料庫連線池原始碼》手寫資料庫連線池資料庫原始碼
- golang連線MySQL時候的連線池設定GolangMySql
- 【JDBC】java連線池模擬測試 連線oracleJDBCJavaOracle
- 【JDBC】使用OracleDataSource建立連線池用於連線OracleJDBCOracle
- 資料庫連線池原理資料庫
- Python實現MySQL連線池PythonMySql
- Flask資料庫連線池Flask資料庫
- HikariCP連線池的學習
- MOSN 原始碼解析 - 連線池原始碼
- python資料庫連線池Python資料庫
- Spring系列之HikariCP連線池Spring
- Java篇-DBUtils與連線池Java
- 安裝配置PGBouncer連線池
- swoole連線池原理解釋
- 某客戶系統tomcat連線池連線異常Tomcat
- ServiceStack.Redis的原始碼分析(連線與連線池)Redis原始碼
- 【MySQL】自定義資料庫連線池和開源資料庫連線池的使用MySql資料庫
- 資料訪問連線池和執行緒池執行緒
- druid連線池常見異常UI
- Druid-目前最好的連線池UI
- ADO.NET連線池寫法
- 聊聊資料庫連線池 Druid資料庫UI
- C#中的連線池管理C#
- Druid MySQL 連線池本地實踐UIMySql
- 最近學習了Http連線池HTTP
- Swoole MySQL 連線池的實現MySql
- Hibernate【查詢、連線池、逆向工程】