Using Occi to connect to the Oracle database under Linux

Source: Internet
Author: User

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:

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.