最近在學習oracle 的c++的編程接口OCCI
注意
以下是引用片段
TOcci
#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
int getConnectCount(){ return _Instance
Connection* getConnect(){ count++;return _Instance
~TOcciDatabase();
protected:
TOcciDatabase(){};
TOcciDatabase(string usr
private:
static TOcciDatabase* _Instance;
static int count;
Environment *env;
Connection *conn;
};
int TOcciDatabase::count =
TOcciDatabase* TOcciDatabase::_Instance =
TOcciDatabase::TOcciDatabase(string usr
{
try
{
env = Environment::createEnvironment (Environment::DEFAULT);
conn = env
}
catch(SQLException ex)
{
cout<<
cout<<
cout<
throw ex;
}
};
TOcciDatabase::~TOcciDatabase()
{
try
{
env
Environment::terminateEnvironment (env);
}
catch(SQLException ex)
{
cout<<
cout<<
cout<
throw ex;
}
};
TOcciDatabase* TOcciDatabase::getInstance(string usr
{
if(_Instance ==
{
_Instance = new TOcciDatabase(usr
}
return _Instance;
};
class TOcciQuery
{
private:
Connection *conn;
Statement *stmt;
bool isAutoCommit;
TOcciQuery(){};
public :
TOcciQuery(Connection *connect){ conn = connect; };
void beginTrans();
void commit();
void roolback();
boolean getAutoCommit();
ResultSet* executeQuery(string sql) ;
void executeUpdate(string sql) ;
void close() { if(stmt != NULL) conn
void close(ResultSet* rs);
};
void TOcciQuery::close(ResultSet* rs)
{
if(rs != NULL)
stmt
if(stmt != NULL)
conn
};
void TOcciQuery::beginTrans()
{
try
{
isAutoCommit = stmt
stmt
}
catch(SQLException ex)
{
cout<<
cout<<
cout<
throw ex;
}
};
void TOcciQuery::commit()
{
try
{
conn
stmt
}
catch(SQLException ex)
{
cout<<
cout<<
cout<
throw ex;
}
};
void TOcciQuery::roolback()
{
try
{
conn
stmt
}
catch(SQLException ex)
{
cout<<
cout<<
cout<
throw ex;
}
};
boolean TOcciQuery::getAutoCommit()
{
boolean result = false;
try
{
result = stmt
}
catch(SQLException ex)
{
cout<<
cout<<
cout<
throw ex;
}
return result;
};
ResultSet* TOcciQuery::executeQuery(string sql)
{
ResultSet*rs = NULL;
try
{
stmt = conn
rs = stmt
}
catch (SQLException ex)
{
cout<<
cout<<
cout<
throw ex;
}
return rs;
};
void TOcciQuery::executeUpdate(string sql)
{
try
{
stmt = conn
stmt
}
catch (SQLException ex)
{
cout<<
cout<<
cout<
throw ex;
}
};
}
#endif /*_OCCIDATABASE_H_*/
測試程序main
// occi
//
#include
#include
int _tmain(int argc
{
using namespace happyever;
TOcciQuery *query = new
TOcciQuery(TOcciDatabase::getInstance(
string strSQL =
ResultSet* rs = query
while(rs
{
std::cout<<
}
query
delete(query);
return
}
From:http://tw.wingwit.com/Article/program/Oracle/201311/18229.html