Linux下使用occi连接Oracle的方法,不需要安装客户端
1. 这里假设你已经安装成功了oracle10g和Eclipse C++环境。
2. 替换"opt/..../db_1/lib"路径下的libocci.so.10.1和libocci10.a。(首先下载occi所需要的库,从这里可以下载到所需要的两个文件)
3.编辑/etc/ld.so.conf,在最后一行输入:/opt.../db_1/lib
4,执行ldconfig
5.
示例,根据互联网修改的
//oracle.h(头文件)
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace oracle::occi;
class dbAccessor
{
public:
dbAccessor();
~dbAccessor();
int get_dbstat();
bool Connect_DB();
void Disconn_DB();
bool ExecuteUpdate(const char* sql);
ResultSet* ExecuteQuery(const char* sql);
void ClearQuery(ResultSet* set);
void Init(const char* dbName,const char* dbUser,const char* dbPass);
void SetDate(unsigned int paramIndex, time_t timeVal);
private:
Environment* m_env;
Connection* m_conn;
Statement* m_stmt;
const char *m_szUser;
const char *m_szPassword;
const char *m_szDbName;
bool bConnected;
};
=======oracle.cpp=====
#include "oracle.h"
using namespace std;
using namespace oracle::occi;
dbAccessor::dbAccessor()
{
bConnected=false;
m_env=0;
m_conn=0;
m_stmt=0;
}
dbAccessor::~dbAccessor()
{
Disconn_DB();
}
void dbAccessor::Init(const char* dbName,const char* dbUser,const char* dbPass)
{
m_szDbName = dbName;
m_szUser = dbUser;
m_szPassword = dbPass;
}
bool dbAccessor::Connect_DB()
{
if(m_env ==0)
m_env = Environment::createEnvironment();
if(m_conn==0){
try {
m_conn=m_env->createConnection(m_szUser,m_szPassword,m_szDbName);
} catch (SQLException& ex) {
m_conn = 0;
cout createStatement(sql);
} catch (SQLException& ex) {
m_stmt = NULL;
cout tm_min,
(timeStruct->tm_sec == 60) ? 0 : timeStruct->tm_sec);
m_stmt->setDate(paramIndex, date);
}