前提是已经安装好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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. SQL Server on Red Hat Enterprise Linux——RHEL上的SQL Server(全截图)

    本文从零开始一步一步介绍如何在Red Hat Enterprise Linux上搭建SQL Server 2017,包括安装系统.安装SQL等相关步骤和方法(仅供测试学习之用,基础篇). 一.   创 ...

  5. 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),以及配置过程中遇到的坑的 ...

  6. SQL Server on Red Hat Enterprise Linux

    本文从零开始一步一步介绍如何在Red Hat Enterprise Linux上搭建SQL Server 2017,包括安装系统.安装SQL等相关步骤和方法(仅供测试学习之用,基础篇). 一.   创 ...

  7. Red Hat Enterprise Linux 6.6安装体验

    Red Hat Enterprise Linux 6.6的安装首界面有五个选项,这跟以前的Red Hat Enterprise Linux 5.x的安装界面是有一些区别的.   安装或者升级现有系统( ...

  8. Red Hat Enterprise Linux 各个版本以及发布日期

    Red Hat Enterprise Linux 7 Release/Update General Availability Date redhat-release Errata Date* Kern ...

  9. 如何安装win10+Red Hat Enterprise Linux双系统?

    1,如何安装win10+Red Hat Enterprise Linux双系统???? 有很多人(没做过调查,可能就我自己想装吧)想要安装Red Hat Enterprise Linux系统,但是又不 ...

随机推荐

  1. 《Odoo开发指南》精选分享—第1章-开始使用Odoo开发(1)

    引言 在进入Odoo开发之前,我们需要建立我们的开发环境,并学习它的基本管理任务. 在本章中,我们将学习如何设置工作环境,在这里我们将构建我们的Odoo应用程序.我们将学习如何设置Debian或Ubu ...

  2. My MES思路图

  3. 仿9GAG制作过程(二)

    有话要说: 这次准备讲述用python爬虫以及将爬来的数据存到MySQL数据库的过程,爬的是煎蛋网的无聊图. 成果: 准备: 下载了python3.7并配置好了环境变量 下载了PyCharm作为开发p ...

  4. 测者的性能测试手册:JVM的监控利器

    测者的性能测试手册:JVM的监控利器 每次聊起性能测试,最后的终结话题就是怎么做优化.其实在Java的复杂项目中都会有内存不足问题.内存泄露问题.线程死锁问题.CPU问题.这些问题工程测试或者是小压力 ...

  5. 用 Heapster 监控集群 - 每天5分钟玩转 Docker 容器技术(176)

    Heapster 是 Kubernetes 原生的集群监控方案.Heapster 以 Pod 的形式运行,它会自动发现集群节点.从节点上的 Kubelet 获取监控数据.Kubelet 则是从节点上的 ...

  6. SQL SERVER 执行动态SQL EXEC

    :普通SQL语句可以用Exec执行 eg: Select * from tableName Exec('select * from tableName') Exec sp_executesql N's ...

  7. centos7中/tmp文件保存天数

    不要在/tmp目录下保存文件,该目录会定期清理文件 /tmp默认保存10天 /var/tmp默认保存30天 配置文件:/usr/lib/tmpfiles.d/tmp.conf 默认配置文件:# Thi ...

  8. TinScrapy-简化的Scrapy原码-查看爬虫的执行流程

    学习了自定义的TinyScrapy框架,整理出以下定注释的代码 from twisted.web.client import getPage,defer from twisted.internet i ...

  9. 连接到 PostgreSQL 数据源(SQL Server 导入和导出向导)

    本主题向你介绍如何从 SQL Server 导入和导出向导的“选择数据源”页或“选择目标”页连接到 PostgreSQL 数据源. 重要 连接到 PostgreSQL 数据库的详细需求和先决条件不在此 ...

  10. 启动期间的内存管理之初始化过程概述----Linux内存管理(九)

    在内存管理的上下文中, 初始化(initialization)可以有多种含义. 在许多CPU上, 必须显式设置适用于Linux内核的内存模型. 例如在x86_32上需要切换到保护模式, 然后内核才能检 ...