OCCI (Oracle C + + call Interface): An application interface for C + + programs to interact with an Oracle database, which is provided to the user in the form of a dynamic connection library. Occi to OCI implementation of the object-level package, the bottom is still OCI
OCCI Connect to Oracle databases under Linux:
1 Install the Oracle client under Linux
2 Download the corresponding Oracle-instantclient-basic-10.2.0.4-1.i386.zip copy it to the Linux Oracle account and extract it to the Instantclient_10_2 directory
Six major steps to achieve OCCI:
1 Creating Environment Variables environment
2 Creating a Connection object connection
3 Creating an Execution object for the SQL statement statement
4 Execute the SQL statement (execute () function, executeupdate () function, executequery () function)
5 processing result set resultset (query result)
6 Closing the connection
Create a table under Linux Oracle database for operation
CREATE TABLE User_info
(
USER_ID int NOT null primary key,
User_name VARCHAR2 (100)
);
[CPP] View plain copy print? addocci.cc #include <iostream> #include <string> # include "occi.h" using namespace std; using namespace oracle::o cci; /******************************* * Add a record to the database ************** / int main () { // Create environment Variables //Environment environment * Env = environment::createenvironment (environment::object); //username is Oracle's username //userpass is Oracle's password &NBSP;&NBSP;//CONNSTR is Oracle's connection string string username = "Hahaya "; string userpass = " HahayA "; string connstr = " 192.168.0.6:1521/ORCL "; //Create connections //connection connection *conn = env->createconnection (USERNAME,&NBSP;USERPASS,&NBSP;CONNSTR); if (conn == null) { cout << "access oracle failed ..." << endl; return 0; } //Create an execution object for an SQL statement //statement statement *st = conn->createstatement (); st->setsql ("Insert into user_info values (1, ' Hahaya ')"); &nbSp; st->executeupdate (); //close connection env->terminateconnection (conn); environment:: Terminateenvironment (env); return 0; }
Before executing the ADDOCCI program:
After executing the ADDOCCI program: