oracle OCCI 的一个简单的包装类的实现
注意:如果需要在vs2005中链接,需要到oracle网站上下载最新的vs2005的occi库文件。
以下是引用片段:
TOcci.h
#ifndef _OCCIDATABASE_H_
#define _OCCIDATABASE_H_
#include
#include
#include
using namespace oracle::occi;
using namespace std;
namespace happyever
{
class TOcciDatabase
{
public:
static TOcciDatabase* getInstance(string usr, string passwd, string db);
int getConnectCount(){ return _Instance->count; };
Connection* getConnect(){ count++;return _Instance->conn; };
~TOcciDatabase();
protected:
TOcciDatabase(){};
TOcciDatabase(string usr, string passwd, string db);
private:
static TOcciDatabase* _Instance;
static int count;
Environment *env;
Connection *conn;
};
int TOcciDatabase::count = 0;
TOcciDatabase* TOcciDatabase::_Instance = 0;
TOcciDatabase::TOcciDatabase(string usr, string passwd, string db)
{
try
{
env = Environment::createEnvironment (Environment::DEFAULT);
conn = env->createConnection (usr, passwd, db);
}
catch(SQLException ex)
{
cout<<"Exception thrown for getConnect"<
cout<<"Error number: "<< ex.getErrorCode() << endl;
cout<
throw ex;
}
};
TOcciDatabase::~TOcciDatabase()