occi 连接池中连接失效

linsen_519 2012-12-25 11:36:43
连接失效导致进程卡死。 过好久才能入库成功或者捕获异常,请问有什么办法能解决问题
这个是创建连接池代码
bool OraConnPool::createConnPool(const std::string& username, const std::string& passwd, const std::string& connectString, int maxCon, int minCon, int incrCon)
{
this->username = username;
this->password = passwd;
this->connstring = connectString;
this->maxCon = maxCon;
this->minCon = minCon;
this->incrCon = incrCon;
setenv("NLS_LANG", "SIMPLIFIED CHINESE_CHINA.ZHS32GB18030", 1);
//setenv("NLS_LANG", "american_america.AL32UTF8", 1);
sErrInfo="";

try
{
//env = Environment::createEnvironment(Environment::DEFAULT);
env = Environment::createEnvironment(Environment::Mode(Environment::OBJECT|Environment::THREADED_MUTEXED));
if (env == NULL)
{
sErrInfo="CreateConnpool Error!";
return false;
}


scp = env->createStatelessConnectionPool(username.c_str(), passwd.c_str(), connectString.c_str(), maxCon, minCon, incrCon, StatelessConnectionPool::HOMOGENEOUS);
scp ->setTimeOut(10000);
if (scp == NULL)
{
Environment::terminateEnvironment(env);
sErrInfo="Connection oracle error!";
return false;
}

sErrInfo="CreateConnpool success! ";
return true;
}
catch(SQLException ex)
{
sErrInfo=ex.getMessage().c_str();
}
return false;
}


这是获取连接代码

Connection* OraConnPool::getConnection()
{
Connection * pConn = NULL;
pConn = scp->getConnection();

return pConn;
}


这个是class
class OraConnPool
{
protected:
OraConnPool();

public:
bool createConnPool(const std::string& username, const std::string& passwd, const std::string& connectString, int maxCon, int minCon, int incrCon);
bool reCreateConnPool();
void destroyConnPool();
string getErrData(void);

Connection * getConnection();
void freeConnection(Connection*);

static OraConnPool* getInstance();
bool checkConnect();
~OraConnPool();
private:
Environment * env;
StatelessConnectionPool * scp;
string sErrInfo;
static OraConnPool* _instance;
std::string username;
std::string password;
std::string connstring;
int maxCon;
int minCon;
int incrCon;
};
...全文
133 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Kobayashi 2012-12-25
  • 打赏
  • 举报
回复
C++不懂。。帮顶

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧