Use of occi____c++ in VC + +

Source: Internet
Author: User
Tags stmt

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

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.