Red Hat Enterprise Linux AS4, C++ OCCI connect Oracle 9i
前提是已经安装好Oracle 9i。
1. 下载对应的ORACLE client安装。
http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
因为没有9i的client提供下载了,我选择最接近的版本下载:
Version 10.1.0.5
Instant Client Package - Basic: All files required to run OCI, OCCI, and JDBC-OCI applications
Download instantclient-basic-linux32-10.1.0.5-20060511.zip (31,413,713 bytes) (cksum - 384697539)
下载之后解压。
2. 先把示例代码给出来:
//oci.cpp
#include <iostream>
#include <string>
#include <occi.h>
using namespace std;
using namespace oracle::occi; int main()
{
Connection *conn;
Environment *env;
Statement *stmt; //build a connection
string struser("scott");
string strpwd("tiger");
string strconn_string("");
cout << "" << endl; env = Environment::createEnvironment(Environment::OBJECT);
cout << "" << endl; conn = env->createConnection(struser, strpwd, strconn_string);
cout << "" << endl; if( NULL != conn)
cout << "conn success" << endl;
else
cout << "conn failed" << endl; //execute sql statement
string strsql("select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual");
stmt = conn->createStatement(strsql);
ResultSet *rset = stmt->executeQuery(); while(rset->next())
{
string time = rset->getString();
cout << "now time:" << time << endl;
} //close resourses
stmt->closeResultSet(rset);
conn->terminateStatement(stmt);
env->terminateConnection(conn);
Environment::terminateEnvironment(env); return ;
}
3. 编译
这里对g++的版本有要求,如果是g++ 3.x.x的,可能会爆出如下错误:
undefined reference to `oracle::occi::Environment::createEnvironment(orac le::occi::Environment::Mode, void*, void* (*)(void*, unsigned int), void* (*)(void*, void*, unsigned int), void (*)(void*, void*))'
网上很多讨论这个错误的,解决办法是安装低版本的g++。
资料(可以不看):解决方案的出处:http://www.dbforums.com/showthread.php?1619980-Makefile-problem-for-OCCI-on-Oracle-9i
If you're getting the following error messages:
undefined reference to `oracle:occi::Environment::createEnvironment(oracle:occi::Environment::Mode, void*, void* (*)(void*, unsigned), void* (*)(void*, void*, unsigned), void (*)(void*, void*))'
and
undefined reference to `oracle:occi::Environment::terminateEnvironment(oracle:occi::Environment*)'
then you're probably running oracle9i on redhat 8.0. to solve this, download and install the following rpm's from this redhat link:
* compat-gcc-7.3-2.96.118.i386.rpm
* compat-gcc-c++-7.3-2.96.118.i386.rpm
* compat-libstdc++-7.3-2.96.118.i386.rpm
* compat-libstdc++-devel-7.3-2.96.118.i386.rpm
and compile with g++296 instead of g++. sure you'll be stuck with g++-2.96, but at least it will compile and run.
在谷歌搜索如下4个rpm包安装:
* compat-gcc-7.3-2.96.118.i386.rpm
* compat-libstdc++-7.3-2.96.118.i386.rpm
* compat-libstdc++-devel-7.3-2.96.118.i386.rpm
* compat-gcc-c++-7.3-2.96.118.i386.rpm
请按照安装上述顺序安装rpm包,因为最后一个依赖于第一二三个。
如果安装的时候报错说“正在安装的g++与系统上存在的g++有冲突”,在rpm后加上-aid --force参数,如下:
sudo rpm -ivh xxx.rpm -aid --force
详情可见这篇文:http://www.cnblogs.com/duanguyuan/p/4118210.html
安装好此版本的g++后,就可以用以下命令编译了:
g++ -o oci -I /opt/oracle/product/rdbms/public/ -I /opt/oracle/product/rdbms/demo/ -I /home/oracle/instantclient10_1/ -L /opt/oracle/product/lib/ -L /opt/oracle/product/rdbms/lib/ oci.cpp -lclntsh -locci /usr/lib/libstdc++.so. -Wall -O -g
注意仔细看上边所包含的编译目录,先看看自己的$ORACLE_HOME在哪里,看看上述的目录都在不在。其中instantclient10_1目录便是第一步下载的Oracle client。
4. 运行
结果如下图

其他参考:
http://blog.csdn.net/gyanp/article/details/6107044
http://oradim.blogspot.com/2009/08/getting-started-with-occi-linux-version.html
Red Hat Enterprise Linux AS4, C++ OCCI connect Oracle 9i的更多相关文章
- Red Hat Enterprise Linux 7.4上安装Oracle 11.2.0.4
1. 配置Yum源及关闭SeLinux [root@localhost ~]# mkdir /media/rhel [root@localhost ~]# mount /dev/cdrom /medi ...
- Deploy Oracle 10.2.0.5 DataGuard on Red Hat Enterprise Linux 6.4
系统:Red Hat Enterprise Linux 6.4 数据库:Oracle 10.2.0.5.0 Patch Set 4 主机:10dg1 192.168.1.91 10dg2192.168 ...
- setting up a IPSEC/L2TP vpn on CentOS 6 or Red Hat Enterprise Linux 6 or Scientific Linux
This is a guide on setting up a IPSEC/L2TP vpn on CentOS 6 or Red Hat Enterprise Linux 6 or Scientif ...
- SQL Server on Red Hat Enterprise Linux——RHEL上的SQL Server(全截图)
本文从零开始一步一步介绍如何在Red Hat Enterprise Linux上搭建SQL Server 2017,包括安装系统.安装SQL等相关步骤和方法(仅供测试学习之用,基础篇). 一. 创 ...
- Configure Always On Availability Group for SQL Server on RHEL——Red Hat Enterprise Linux上配置SQL Server Always On Availability Group
下面简单介绍一下如何在Red Hat Enterprise Linux上一步一步创建一个SQL Server AG(Always On Availability Group),以及配置过程中遇到的坑的 ...
- SQL Server on Red Hat Enterprise Linux
本文从零开始一步一步介绍如何在Red Hat Enterprise Linux上搭建SQL Server 2017,包括安装系统.安装SQL等相关步骤和方法(仅供测试学习之用,基础篇). 一. 创 ...
- Red Hat Enterprise Linux 6.6安装体验
Red Hat Enterprise Linux 6.6的安装首界面有五个选项,这跟以前的Red Hat Enterprise Linux 5.x的安装界面是有一些区别的. 安装或者升级现有系统( ...
- Red Hat Enterprise Linux 各个版本以及发布日期
Red Hat Enterprise Linux 7 Release/Update General Availability Date redhat-release Errata Date* Kern ...
- 如何安装win10+Red Hat Enterprise Linux双系统?
1,如何安装win10+Red Hat Enterprise Linux双系统???? 有很多人(没做过调查,可能就我自己想装吧)想要安装Red Hat Enterprise Linux系统,但是又不 ...
随机推荐
- 使用vue-cli 初始化 vue 项目
1. 安装nodejs 2. 安装 vue-cli npm install -g vue-cli 安装前可以通过设置代理为淘宝仓库地址,以加快下载速度. npm config set registry ...
- 【20190415】JavaScript-事件流与stopPropagation()、stopImmediatePropagation()的误区解析
这两天仔细看了一下MDN上关于事件流机制和相关方法的文档,发现有个很大的误区.过去我一直以为stopPropagation()就是用来阻止事件冒泡的,甚至很多博客和菜鸟教程上都是这样写的.但实际上文档 ...
- 小记 xian80 坐标转换 wgs84
转坐标这个问题是个老生常谈的话题了. 昨天遇到同事求助将 xian80的平面坐标转换到2000下. 想了一下,因为暂时还没有现成的2000的dwg数据可用,只能暂时以wgs84的为准了,然而有个问题, ...
- Android远程桌面助手之系统兼容篇
Android远程桌面助手理论上兼容Android4.4至Android8.1之间所有的原生安卓系统,其他第三方ROM,如MIUI.Flyme.EMUI和Smartisan OS等也都陆续测试过,目前 ...
- 关于MongoDB时间格式转换和时间段聚合统计的用法总结
一 . 背景需求 在日常的业务需求中,我们往往会根据时间段来统计数据.例如,统计每小时的下单量:每天的库存变化,这类信息数据对运营管理很重要. 这类数据统计依赖于各个时间维度,年月日.时分秒都有可能. ...
- js实现表格无缝滚动效果
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- 最小生成树(Prim算法)
Java实现Prim算法 package com.java; import java.util.*; /** * 普里姆算法—Prim算法 * 算法思路:将图中所有的顶点分为两类:树顶点(已被选入生成 ...
- Oracle 12c RAC 安装文档
参考文档: https://docs.oracle.com/en/database/oracle/oracle-database/12.2/cwlin/index.html https://docs. ...
- SQLServer数据库差异备份
差异备份 (differential backup)定义 一种数据备份,基于完整数据库或部分数据库或一组数据文件或文件组(差异基准)的最新完整备份,并且仅包含自确定差异基准以来发生更改的数据. 使用S ...
- SQLAlchemy增删改查
sqlalchemy中让MySQL支持中文字符 engine = create_engine("mysql+pymysql://root:mysql8@localhost/mysqltest ...