Build a C ++ runtime environment on CentOS6.6 and connect to the Oracle database

Source: Internet
Author: User
Tags dname
Build a C ++ runtime environment on CentOS6.6 and connect to the Oracle database

Build a C ++ runtime environment on CentOS 6.6 and connect to the Oracle database

# Yum install gcc-c ++

Note: Both gcc-c ++ and libstdc ++-devel are installed.

2. Check whether g ++ is successfully installed.
[Root @ MyRHEL desktop] # g ++-v

Use built-in specs.

Goals: x86_64-RedHat-linux

Configuration :.. /configure -- prefix =/usr -- mandir =/usr/share/man -- infodir =/usr/share/info -- with-bugurl = http://bugzilla.redhat.com/bugzilla -- enable-bootstrap -- enable-shared -- enable-threads = posix -- enable-checking = release -- with-system-zlib -- enable-_ cxa_atexit -- disable-libunwind-exceptions -- enable-gnu-unique-object -- enable- ages = c, c ++, objc, obj-c ++, java, fortran, ada -- enable-java-awt = gtk -- disable-dssi -- with-java-home =/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre -- enable-libgcj-multifile -- enable-java -maintainer-mode -- with-ecj-jar =/usr/share/java/eclipse-ecj.jar -- disable-libjava-multilib -- with-ppl -- with-cloog -- with-tune = generic -- with-arch_32 = i686 -- build = x86_64-redhat-linux

Thread model: posix

Gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)

3. Test

(1) Test the c language program testc. c.
# Include
Int main ()
{
Printf ("Hello C! \ N ");
Return 0;
}

Run:
# Gcc testc. c-o testc
#./Testc

(2) test C ++ program test. cpp
# Include
Using namespace std;
Int main ()
{
Cout <"Come up and C ++ me some time .";
Cout <endl;
Cout <"You won't regret it! "<Endl;
Return 10;
}

Run:
# G ++-o test1 test. cpp
#./Test1

4. Install OracleClient

Mainly install oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm and oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm.
# Rpm-ivh oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm
# Rpm-ivh oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64.rpm

5 configuration

(1) configure the ld. so. conf file and enter the following content:
# Vi/etc/ld. so. conf
Include ld. 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.1 localhost. localdomain localhost4 localhost4.localdomain4
: 1 localhost. localdomain localhost6 localhost6.localdomain6
192.168.48.128 MyRHEL

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

# Include

# Include

Using namespace std;

Using namespace oracle: occi;

Int main ()

{

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" <

String strsql ("select deptno, dname from dept ");

Stmt = conn-> createStatement (strsql );

ResultSet * rset = stmt-> executeQuery ();

While (rset-> next ()){

Int deptno = rset-> getInt (1 );

String dname = rset-> getString (2 );

Cout <"deptno =" <

}

Stmt-> closeResultSet (rset );

Conn-> terminateStatement (stmt );

Env-> terminateConnection (conn );

Environment: terminateEnvironment (env );

Return0;

}

(2) Compile and run:
[Root @ MyRHEL test] # g ++-o connclient. cpp-L/usr/lib/oracle/11.2/client64/lib-I/usr/include/oracle/11.2/client64/-locci-lclntsh/usr/lib64/libstdc ++. so.6
[Root @ MyRHEL test] #./connclient
Conn success
Deptno = 10, dname = ACCOUNTING
Deptno = 20, dname = RESEARCH
Deptno = 30, dname = SALES
Deptno = 40, dname = OPERATIONS

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.