Use OCCI to connect to Oracle databases in Linux

Source: Internet
Author: User

OCCI(Oracle C ++ Call Interface):C ++Program andOracleThe database implements interactive application interfaces, which are provided to users in the form of dynamic connection libraries.OCCIPairOCIImplements object-level encapsulation, and its underlying layer is stillOCI

OCCIConnectionLinuxUnderOracleDatabase:

1InstallLinuxUnderOracleClient

2Download the correspondingOracle-instantclient-basic-10.2.0.4-1.i386.zipCopy itLinuxOfOracleAnd decompress itInstantclient_10_2Directory

ImplementationOCCISix steps:

1Create Environment VariablesEnvironment

2Create a connection objectConnection

3CreateSQLStatement execution objectStatement

4RunSQLStatement (Execute() Function,ExecuteUpdate ()Function,ExecuteQuery() Function)

5Processing result setResultSet(Query results)

6Close connection

 

InLinuxOfOracleCreate a table under the database for operations

Create table user_info

(

User_id int not null primary key,

User_name varchar2 (100)

);

 

 
  1. // AddOcci. cc
  2. # Include <iostream>
  3. # Include <string>
  4. # Include "occi. h"
  5. Using NamespaceStd;
  6. Using NamespaceOracle: occi;
  7. /******************************* 
  8. * Add a record to the database 
  9. *******************************/
  10. IntMain ()
  11. {
  12. // Create an environment variable
  13. // Environment
  14. Environment * env = Environment: createEnvironment (Environment: OBJECT );
  15. // Username is the username of oracle
  16. // Userpass is the oracle Password
  17. // Connstr is the connection string of oracle.
  18. String username ="Hahaya";
  19. String userpass ="Hahaya";
  20. String connstr =& Quot; 192.168.0.6: 1521/orcl & quot";
  21. // Create a connection
  22. // Connection
  23. Connection * conn = env-> createConnection (username, userpass, connstr );
  24. If(Conn = NULL)
  25. {
  26. Cout <"Access oracle failed ..."<Endl;
  27. Return0;
  28. }
  29. // Create an SQL statement execution object
  30. // Statement
  31. Statement * st = conn-> createStatement ();
  32. St-> setSQL ("Insert into user_info values (1, 'hahaay ')");
  33. St-> executeUpdate ();
  34. // Close the connection
  35. Env-> terminateConnection (conn );
  36. Environment: terminateEnvironment (env );
  37. Return0;
  38. }
  • 1
  • 2
  • Next Page

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.