Red Hat Enterprise Linux AS4, C + + OCCI connect Oracle 9i

Source: Internet
Author: User
Tags stmt

The premise is that Oracle 9i is already installed.

1. Download the corresponding Oracle client installation.

Http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html

Since there is no 9i client available to download, I choose the closest version to download:

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)

Unzip after download.

2. Give the sample code first:
//oci.cpp
#include <iostream>#include<string>#include<occi.h>using namespacestd;using namespaceOracle::occi;intMain () {Connection*Conn; Environment*env; Statement*stmt; //Build a connection stringStruser ("Scott"); stringStrpwd ("Tiger"); stringStrconn_string (""); cout<<"1"<<Endl; Env=environment::createenvironment (Environment::object); cout<<"2"<<Endl; Conn= env->createconnection (struser, Strpwd, strconn_string); cout<<"3"<<Endl; if(NULL! =conn) cout<<"Conn Success"<<Endl; Elsecout<<"Conn Failed"<<Endl; //Execute SQL statement stringstrSQL ("Select To_char (sysdate, ' Yyyy-mm-dd hh24:mi:ss ') from dual"); stmt= conn->createstatement (strSQL); ResultSet*rset = stmt->ExecuteQuery (); while(rset->Next ()) { stringTime = rset->getstring (1); cout<<"Now time :"<< Time <<Endl; } //Close ResoursesStmt->Closeresultset (RSet); Conn-terminatestatement (stmt); Env-terminateconnection (conn); Environment::terminateenvironment (env); return 0;}
3. Compiling

There are requirements for the g++ version, and if it is g++ 3.x.x, the following error may occur:

int int), void (*) (void*, void*))'

Many online discussions of this error, the solution is to install the lower version of the g++.

Information (can not see): The source of the solution: 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'll compile and run.

The following 4 RPM packages are installed in Google search:

* 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

Please install the RPM package according to the order installed, because the last one depends on the 123th one.

If the error is installed when said "the installation of the g++ and the system exists on the g++ conflict", after the rpm with -aid--force parameters, as follows:

sudo rpm-ivh xxx.rpm -aid--force

Details can be seen in this article: http://www.cnblogs.com/duanguyuan/p/4118210.html

Once you have installed this version of g++, you can compile it with the following command:

g++296 -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. 5 -wall-o-G

Take a closer look at the top of the compilation directory included, first look at your own $oracle_home where, see the above directories are not. The Instantclient10_1 directory is the first Oracle client to download.

4. Running

Results such as

Other references:

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.