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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 連線池
- Go連線池Go
- HTTP連線池HTTP
- django連線池Django
- Http持久連線與HttpClient連線池HTTPclient
- 連線池和連線數詳解
- ElasticSearch連線池建立Elasticsearch
- 自定義連線池
- golang tcp連線池GolangTCP
- Oracle 連線池配置Oracle
- oracle occi 連線池Oracle
- Resin 配置連線池
- [尋]連線池例子
- proxool連線池 配置
- 連線池 druidUI
- java連線池解決連線中斷Java
- proxool連線池如何使用SSL方式連線?
- Golang SQL連線池梳理GolangSQL
- go 語言連線池Go
- DBCP連線池原理分析
- Hibernate連線池配置
- Tomcat連線池使用Tomcat
- 資料庫連線池資料庫
- 《四 資料庫連線池原始碼》手寫資料庫連線池資料庫原始碼
- 資料庫連線池-Druid資料庫連線池原始碼解析資料庫UI原始碼
- 【JDBC】java連線池模擬測試 連線oracleJDBCJavaOracle
- 【JDBC】使用OracleDataSource建立連線池用於連線OracleJDBCOracle
- golang連線MySQL時候的連線池設定GolangMySql
- 執行緒池、連線池、物件池從0到1執行緒物件
- Java篇-DBUtils與連線池Java
- swoole連線池原理解釋
- 資料庫連線池原理資料庫
- Tomcat 的 JDBC 連線池TomcatJDBC
- Proxool資料庫連線池資料庫
- JAVA資料庫連線池Java資料庫
- Proxool 連線池的配置使用
- tomcat連線池問題Tomcat
- 有關連線池的疑惑。