Red Hat Enterprise Linux AS4, C ++ OCCI connect Oracle 9i
Red Hat Enterprise Linux AS4, C ++ OCCI connect Oracle 9i, provided that Oracle 9i has been installed.
1. Download the corresponding ORACLE client installation.
Http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
Because the 9i client does not provide download, I select the closest version for 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)
Download and decompress the package.
2. First, give the sample code:
// 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 <"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;
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 (1 );
Cout <"now time:" <time <endl;
}
// Close resourses
Stmt-> closeResultSet (rset );
Conn-> terminateStatement (stmt );
Env-> terminateConnection (conn );
Environment: terminateEnvironment (env );
Return 0;
}
3. Compile
The following error may occur if the version of g ++ is 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 *))'
This error is often discussed on the Internet. The solution is to install a lower version of g ++.
--------------------------------------------------------------------------------
Information (can not see): solution Source: 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.
--------------------------------------------------------------------------------
Install the following four rpm packages:
* 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
Download from the FTP server No. 1 of the customer's home:
------------------------------------------ Split line ------------------------------------------
FTP address: ftp://ftp1.bkjia.com
Username: ftp1.bkjia.com
Password: www.bkjia.com
On October 11, 2016, LinuxIDC.com \ March \ Red Hat Enterprise Linux AS4, C ++ OCCI connect Oracle 9i \
For the download method, see
------------------------------------------ Split line ------------------------------------------
Install the rpm package in the above order, because the last one depends on the first, second, and third.
If an error is reported during installation, saying "The g ++ being installed conflicts with the g ++ on the system", add the-aid -- force parameter after rpm, as shown below:
Sudo rpm-ivh xxx. rpm-aid -- force
After installing 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
Pay attention to the compilation Directory included in the above carefully. First, check where your $ ORACLE_HOME is and see if all the above directories are located. The instantclient10_1 directory is the Oracle client downloaded in step 1.
4. Run
The result is as follows: