#vi/etc/ld.so.conf
includeld.so.conf.d/*.conf
/usr/lib/oracle/11
.2
/client64/lib
(2) configure the/etc/hosts file (enter the IP address and Host Name of the Linux host) and enter the following content:
#vi/etc/hosts
127.0.0.1localhostlocalhost.localdomainlocalhost4localhost4.localdomain4
::1localhostlocalhost.localdomainlocalhost6localhost6.localdomain6
192.168.48.128MyRHEL
6. Test the connection to the Oracle database
(1) create a connclient. cpp file and enter the following content:
[Root @ MyRHEL test] # vi connclient. cpp
# Include <iostream>
# Include <string>
# Include <occi. h>
UsingNamespacestd;
UsingNamespaceoracle: Occi;
Intmain()
{
Environment* Env;
Connection* Conn;
Statement* Stmt;
String struser("Scott");
String strpwd("Orcl0991");
String strconn_string("10.208.17.206: 1521/xe");
Env= Environment: CreateEnvironment(Environment: OBJECT);
Conn= Env-> CreateConnection(Struser, Strpwd, Strconn_string);
If(NULL! = Conn)
Cout<"Conn success"<Endl;
Else
Cout<"Conn failed"<Endl;
String strsql("Select deptno, dname from dept");
Stmt= Conn-> CreateStatement(Strsql);
ResultSet* Rset= Stmt-> ExecuteQuery();
While(Rset-> Next()){
Intdeptno= Rset-> GetInt(1);
String dname= Rset-> GetString(2);
Cout<"Deptno ="<Deptno<", Dname ="<Dname<Endl;
}
Stmt-> CloseResultSet(Rset);
Conn-> TerminateStatement(Stmt);
Env-> TerminateConnection(Conn);
Environment: TerminateEnvironment(Env);
Return0;
}
(2) Compile and run:
[root@MyRHELtest]#g++-oconnclientconnclient.cpp-L/usr/lib/oracle/11.2/client64/lib-I/usr/include/oracle/11.2/client64/-locci-lclntsh/usr/lib64/libstdc++.so.6
[root@MyRHELtest]#./connclient
connsuccess
deptno=10,dname=ACCOUNTING
deptno=20,dname=RESEARCH
deptno=30,dname=SALES
deptno=40,dname=OPERATIONS