ocilib连接池

#include "ocilib.h" #define MAX_THREADS 50 #define MAX_CONN 10 #define SIZE_STR 260 void worker(OCI_Thread *thread, void *data) { OCI_Connection *cn = OCI_PoolGetConnection(data, NULL); char str[SIZE_STR+1]; /* application work here */ str[0] = 0; OCI_Immediate(cn, "select to_char(sysdate, 'YYYYMMDD HH24:MI:SS') from dual", OCI_ARG_TEXT, str); printf("%s\n", str); /* ... */ OCI_ConnectionFree(cn); } int main(void) { OCI_Thread *th[MAX_THREADS]; OCI_ConnPool *pool; int i; if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT | OCI_ENV_THREADED)) return EXIT_FAILURE; /* create pool */ pool = OCI_PoolCreate("db", "usr", "pwd", OCI_POOL_CONNECTION, OCI_SESSION_DEFAULT, 0, MAX_CONN, 1); /* create threads */ for (i = 0; i < MAX_THREADS; i++) { th[i] = OCI_ThreadCreate(); OCI_ThreadRun(th[i], worker, pool); } /* wait for threads and cleanup */ for (i = 0; i < MAX_THREADS; i++) { OCI_ThreadJoin(th[i]); OCI_ThreadFree(th[i]); } OCI_PoolFree(pool); OCI_Cleanup(); return EXIT_SUCCESS; }


   ocilib在新的版本中已经有支持连接池。OCI_PoolCreate函数实现建立一个池,OCI_PoolFree释放。OCI_PoolGetConnection 获取一个连接。

   这是ocilib自己的示例

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值