1. Introduction
Access to Oracle databases under Windows can be accessed using ADO,ADO.NET,OLEDB,ODBC, Cross-platform Occi, which is the fastest, and Oracle-supplied OCCI is most complete for Oracle support.2. Install Occi SDKThe OCCI SDK is included with Oracle clients and can be found in the following locations: Header: C:\oracle\ora92\oci\include library file: C:\oracle\ora92\oci\lib\msvc recommended to install Oracle Instant Client (Instant Client), it also contains a OCCI SDK. Header file: Instantclient_10_2\sdk\include library file: instantclient_10_2\sdk\lib\msvc3. Compile Occi programabout how to compile in VC, debugging OCCI procedures, see "VC + + debugging OCCI program key Settings"4.OCCI Programming Steps4.1 Connecting to the databaseCreate OCCI context Environment Environment *env = environment::createenvironment (); ASSERT (env!= NULL); Create a database connection Connection *conn = env->createconnection ("UID", "pwd", "oracle_svr_name"); ..//TODO: Insert your own code//close connection to Env-> terminateconnection (conn); Release environment:: Terminateenvironment (env);4.2 Execute the basic SQL statementCreate SQL statement control handle Statement *stmt = Conn->createstatement ();a. Executing a generic SQL statementstmt-> executeupdate ("Create TABLE basket_tab (Fruit VARCHAR2)"); stmt-> executeupdate ("delete Basket_tab");B. Reusing SQL statements, parameterized SQL statements: 1,:2 is a parameter placeholder stmt-> setsql ("Insert into Basket_tab VALUES (: 1,:2)"); The first parameter stmt-> setstring (1, "bananas"); The second parameter stmt-> setint (2, 5); stmt-> executeupdate ();c. Modify multiple rows of data at one timeThe maximum number of iterations allowed, note that this parameter needs to execute the stmt-> setmaxiterations (int maxiterations) before the SETXXX series function; Specifies the size of a parameter, string and byte require stmt-> setmaxparamsize (int parameterindex, int maxparamsize); For (...) {///first parameter stmt->setstring (1, "bananas"); The second parameter Stmt->setint (2, 5); Add a row of records, similar to the ADO AddNew pstmt->additeration (); } stmt-> executeupdate ();D. Executing a query: Getting the result set (recordset) ResultSet *rs = stmt->executequery ("SELECT * from Basket_tab"); While (Rs->next ()) { string fruit = rs->getstring (1); // Get the "a" As String int quantity = rs->getint (2); //get the second column as int} //close result set