class mConnectionPool
{
public:
mConnectionPool();
~mConnectionPool();
int connectDB(char *userName,char *userPassWord,char *dbName);
Connection * getConnection();
int closeConnection(Connection *con);
private:
oracle::occi::Environment *env;
ConnectionPool *connPool;
char m_userName[128+1];
char m_userPassWord[128+1];
char m_dbName[128+1];
int maxConn;
int minConn;
int incrConn;
};
mConnectionPool::mConnectionPool()
{
env=NULL;
connPool=NULL;
memset(m_userName,0,sizeof(m_userName));
memset(m_userPassWord,0,sizeof(m_userPassWord));
memset(m_dbName,0,sizeof(m_dbName));
maxConn=10;
minConn=5;
incrConn=1;
}
mConnectionPool::~mConnectionPool()
{
try{
env->terminateConnectionPool(connPool);
Environment::terminateEnvironment(env);
}
catch(SQLException &ex)
{
cout<<"release connection error:"<<ex.what()<<endl;
}
}
int mConnectionPool::connectDB(char *userName,char *userPassWord,char *dbName)
{
strncpy(m_userName,userName,sizeof(m_userName)-1);
strncpy(m_userPassWord,userPassWord,sizeof(m_userPassWord)-1);
strncpy(m_dbName,dbName,sizeof(m_dbName)-1);
try{
env = oracle::occi::Environment::createEnvironment(Environment::DEFAULT);
connPool = env->createConnectionPool(m_userName,m_userPassWord,m_dbName,minConn,maxConn,incrConn);
}
catch(SQLException &ex)
{
cout<<"create connPool error:"<<ex.what()<<endl;
return 1;
}
return 0;
}
int mConnectionPool::closeConnection(Connection *con)
{
try{
connPool->terminateConnection(con);
}
catch(SQLException &ex)
{
cout<<"release connection error:"<<ex.what()<<endl;
return 1;
}
return 0;
}
Connection * mConnectionPool::getConnection()
{
Connection *conn;
try{
conn=connPool->createConnection(m_userName,m_userPassWord);
}
catch(SQLException &exp)
{
cout<<"get conn error:"<<exp.what()<<endl;
return NULL;
}
return conn;
}
{
public:
mConnectionPool();
~mConnectionPool();
int connectDB(char *userName,char *userPassWord,char *dbName);
Connection * getConnection();
int closeConnection(Connection *con);
private:
oracle::occi::Environment *env;
ConnectionPool *connPool;
char m_userName[128+1];
char m_userPassWord[128+1];
char m_dbName[128+1];
int maxConn;
int minConn;
int incrConn;
};
mConnectionPool::mConnectionPool()
{
env=NULL;
connPool=NULL;
memset(m_userName,0,sizeof(m_userName));
memset(m_userPassWord,0,sizeof(m_userPassWord));
memset(m_dbName,0,sizeof(m_dbName));
maxConn=10;
minConn=5;
incrConn=1;
}
mConnectionPool::~mConnectionPool()
{
try{
env->terminateConnectionPool(connPool);
Environment::terminateEnvironment(env);
}
catch(SQLException &ex)
{
cout<<"release connection error:"<<ex.what()<<endl;
}
}
int mConnectionPool::connectDB(char *userName,char *userPassWord,char *dbName)
{
strncpy(m_userName,userName,sizeof(m_userName)-1);
strncpy(m_userPassWord,userPassWord,sizeof(m_userPassWord)-1);
strncpy(m_dbName,dbName,sizeof(m_dbName)-1);
try{
env = oracle::occi::Environment::createEnvironment(Environment::DEFAULT);
connPool = env->createConnectionPool(m_userName,m_userPassWord,m_dbName,minConn,maxConn,incrConn);
}
catch(SQLException &ex)
{
cout<<"create connPool error:"<<ex.what()<<endl;
return 1;
}
return 0;
}
int mConnectionPool::closeConnection(Connection *con)
{
try{
connPool->terminateConnection(con);
}
catch(SQLException &ex)
{
cout<<"release connection error:"<<ex.what()<<endl;
return 1;
}
return 0;
}
Connection * mConnectionPool::getConnection()
{
Connection *conn;
try{
conn=connPool->createConnection(m_userName,m_userPassWord);
}
catch(SQLException &exp)
{
cout<<"get conn error:"<<exp.what()<<endl;
return NULL;
}
return conn;
}