Linux平台下OCCI环境搭建
相关文件:oracle_client_11gR2.tar.gz
1解压文件:
tar -xzvf oracle_client_11gR2.tar.gz
mv instantclient_11_2 /opt/
设置环境变量
vim ~/.bash_profile 文件最后添加
# 请把已经环境变量设置到对应的文件中
# 可以是当前用户的 ~/.bashrc文件, 也可以是系统的 /etc/profile文件
?
# OCCI_HOME 该环境变量的路径需要做对应修改
export OCCI_HOME=/opt/instantclient_11_2
export OCCI_INCLUDE_DIR=$OCCI_HOME/sdk/include
export OCCI_LIBRARY_PATH=$OCCI_HOME
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OCCI_LIBRARY_PATH
# 程序编译是搜索的库目录
export LIBRARY_PATH=$LIBRARY_PATH:$OCCI_LIBRARY_PATH
# 程序编译时搜索的头文件目录
export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:$OCCI_INCLUDE_DIR
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"
使修改生效
source ~/.bash_profile
测试程序
#include <iostream>
#include <occi.h>
using namespace std;
using namespace oracle::occi;
?
int main()
{
const string userName = "SCOTT";
const string password = "11";
const string connString = "192.168.1.159:1521/orcl";
try
{
Environment *env = Environment::createEnvironment(Environment::DEFAULT);
Connection *con = env->createConnection(userName, password, connString);
cout << "Success to connect!" << endl;
Statement *stmt = con->createStatement();
stmt->setSQL("select * from dept");
ResultSet *rs = stmt->executeQuery();
while (rs->next())
{
cout << "ID:" << rs->getInt(1) << endl;
}
con->terminateStatement(stmt);
env->terminateConnection(con);
Environment::terminateEnvironment(env);
}
catch (SQLException &ex)
{
cout << ex.what() << endl;
}
?
return 0;
}
g++ -std=c++11 -lnnz11 -lclntsh -locci test.cpp
|