c++ && occi 开发指南
1. 安装库
instantclient-sdk-linux.x64-12.2.0.1.0.zip (包含头文件)
instantclient-basic-linux.x64-12.2.0.1.0.zip
2. 编译
OCCI_INCLUDE_DIR=/home/fuanda/occi_test/instantclient_12_2/sdk/include
OCCI_LIBRARY_PATH=/home/fuanda/occi_test/instantclient_12_2
export LD_LIBRARY_PATH=$OCCI_LIBRARY_PATH:$LD_LIBRARY_PATH
g++ -o main main.cpp -I$OCCI_INCLUDE_DIR -L$OCCI_LIBRARY_PATH -locci -lclntsh
============================================
#include <iostream>
#define LINUXOCCI //避免函数重定义错误
#include <occi.h>
using namespace std;
using namespace oracle::occi;
int main()
{
cout << "start\n";
Environment *env=Environment::createEnvironment(Environment::THREADED_MUTEXED);
cout<<"success"<<endl;
string name = "lihl";
string pass = "123456";
string srvName = "192.168.1.125:1521/margin";
try
{
Connection *conn = env->createConnection(name, pass, srvName);
cout<<"conn success"<<endl;
env->terminateConnection(conn);
}
catch(SQLException e)
{
cout<< "exception: " << e.what()<<endl;
return -1;
}
Environment::terminateEnvironment(env);
cout<<"end!"<<endl;
return 0;
}
============================================
3. 运行
export ORACLE_HOME=/home/fuanda/occi_test/instantclient_12_2
#export NLS_LANG='simplified chinese'_china.ZHS16GBK
export LD_LIBRARY_PATH=$ORACLE_HOME:$LD_LIBRARY_PATH
./main
4. 发布是仅需
1. 安装库
instantclient-sdk-linux.x64-12.2.0.1.0.zip (包含头文件)
instantclient-basic-linux.x64-12.2.0.1.0.zip
2. 编译
OCCI_INCLUDE_DIR=/home/fuanda/occi_test/instantclient_12_2/sdk/include
OCCI_LIBRARY_PATH=/home/fuanda/occi_test/instantclient_12_2
export LD_LIBRARY_PATH=$OCCI_LIBRARY_PATH:$LD_LIBRARY_PATH
g++ -o main main.cpp -I$OCCI_INCLUDE_DIR -L$OCCI_LIBRARY_PATH -locci -lclntsh
============================================
#include <iostream>
#define LINUXOCCI //避免函数重定义错误
#include <occi.h>
using namespace std;
using namespace oracle::occi;
int main()
{
cout << "start\n";
Environment *env=Environment::createEnvironment(Environment::THREADED_MUTEXED);
cout<<"success"<<endl;
string name = "lihl";
string pass = "123456";
string srvName = "192.168.1.125:1521/margin";
try
{
Connection *conn = env->createConnection(name, pass, srvName);
cout<<"conn success"<<endl;
env->terminateConnection(conn);
}
catch(SQLException e)
{
cout<< "exception: " << e.what()<<endl;
return -1;
}
Environment::terminateEnvironment(env);
cout<<"end!"<<endl;
return 0;
}
============================================
3. 运行
export ORACLE_HOME=/home/fuanda/occi_test/instantclient_12_2
#export NLS_LANG='simplified chinese'_china.ZHS16GBK
export LD_LIBRARY_PATH=$ORACLE_HOME:$LD_LIBRARY_PATH
./main
4. 发布是仅需
instantclient-basic-linux.x64-12.2.0.1.0.zip
============================================================
python&&cx_Oracle 开发指南
1. 安装cx_Oracle
pip install cx_Oracle
2. 下载 instantclient-basic-linux.x64-12.2.0.1.0.zip, 安装库instantclient
mkdir -p /opt/oracle
cd /opt/oracle
unzip instantclient-basic-linux.x64-12.2.0.1.0.zip
3. 安装libaio 包
yum install libaio
4. 配置库路径
如果没有其他oracle 库版本,可以使用
echo /opt/oracle/instantclient_12_2 > /etc/ld.so.conf.d/oracle-instantclient.conf
ldconfig
否则
export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_2:$LD_LIBRARY_PATH