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 ;}