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)
);
- // AddOcci. cc
- # Include <iostream>
- # Include <string>
- # Include "occi. h"
- Using NamespaceStd;
- Using NamespaceOracle: occi;
- /*******************************
- * Add a record to the database
- *******************************/
- IntMain ()
- {
- // Create an environment variable
- // Environment
- Environment * env = Environment: createEnvironment (Environment: OBJECT );
- // Username is the username of oracle
- // Userpass is the oracle Password
- // Connstr is the connection string of oracle.
- String username ="Hahaya";
- String userpass ="Hahaya";
- String connstr =& Quot; 192.168.0.6: 1521/orcl & quot";
- // Create a connection
- // Connection
- Connection * conn = env-> createConnection (username, userpass, connstr );
- If(Conn = NULL)
- {
- Cout <"Access oracle failed ..."<Endl;
- Return0;
- }
- // Create an SQL statement execution object
- // Statement
- Statement * st = conn-> createStatement ();
- St-> setSQL ("Insert into user_info values (1, 'hahaay ')");
- St-> executeUpdate ();
- // Close the connection
- Env-> terminateConnection (conn );
- Environment: terminateEnvironment (env );
- Return0;
- }