使用cx_Oracle 创建会话池sessionpool 及使用
程序员文章站
2024-03-24 21:04:10
...
参考其他文章:https://blog.csdn.net/danevc/article/details/54966443
参考官网文章:http://cx-oracle.readthedocs.io/en/latest/module.html#cx_Oracle.SessionPool
按照官网的思路比较好:
使用cx_Oracle.
SessionPool
返回一个会话池对象,这个对象调用 acquire()
就可以返回一个连接对象了。
Create and return a session pool object. Thisallows for very fast connections to the database and is of primary use in aserver where the same connection is being made multiple times in rapidsuccession (a web server, for example).
If the connection type is specified, all calls toacquire()
will create connection objects of that type,rather than the base type defined at the module level.
代码示例:
#创建一个会话池
connPool=cx_Oracle.SessionPool(user='',password='',dsn='IP/instance',min=1,max=500,increment=1)
#从会话池中返回一个连接
conn = connPool.acquire() #这一步等同于conn = cx_Oracle.connection(....)
#关闭连接
conn.close()
#释放会话池
connPool.release()