Oracle C ++ call interface (occi)

Source: Internet
Author: User

I have studied some database interfaces before, such as OCI. Today I have studied occi specially. occi is a class library encapsulated on the basis of OCI for C ++ developers, it is organized using object-oriented methods, while OCI is a C language interface, function calls are quite complex, and encapsulation is not easy. Speak nonsense.CodeRight.

 

# Include <iostream> # include <occi. h> # include <assert. h> using namespace ORACLE: occi; using namespace STD; int main () {environment * Env = NULL; connection * conn = NULL; statement * stmt = NULL; resultset * rs = NULL; string username = "Scott"; // username string Password = "tiger"; // password string connstring = "// localhost: 1521/orcl "; // connection string SQL, strname; int errnum = 0; string errmsg = ""; ENV = environment: createen Vironment (); // create an environment variable try {assert (ENV! = NULL); Conn = env-> createconnection (username, password, connstring); // create a database connection object stmt = Conn-> createstatement (); // create a statement object} catch (sqlexception ex) {errnum = ex. geterrorcode (); errmsg = ex. getmessage (); cout <"error number:" <errnum <Endl; // retrieves the Exception Code cout <errmsg <Endl; // retrieve exception information} SQL = "select ID, name from student where ID >=: 1"; // concatenate an SQL statement int id = 2; stmt-> setsql (SQL); // set the SQL statement to stmt-> setint (1, ID) in the statement object; try {char buffer [4096]; // buffer rs = stmt-> executequery (); // execute the SQL statement int recordcnt = RS-> getnumarrayrows (); RS-> setcharacterstreammode ); while (RS-> next () {// retrieve data unsigned int length = 0; unsigned int size = 500; stream * stream = RS-> getstream (2); While (Stream-> Status () = stream: ready_for_read) {Length + = stream-> readbuffer (buffer + length, size) ;}cout <"read" <length <"bytes into the buffer" <Endl ;}cout <"select-success" <Endl ;} catch (sqlexception ex) {cout <"error number:" <ex. geterrorcode () <Endl; // retrieves the Exception Code cout <ex. getmessage () <Endl; // retrieve exception information} Conn-> terminatestatement (stmt); // terminate the statement object env-> terminateconnection (conn ); // disconnect the database. Environment: terminateenvironment (ENV); // terminate the environment variable return 1 ;}

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.