linux下使用C语言连接oracle数据库

2018-10-24  本文已影响0人  明明就_c565

下载地址

https://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

需要注册oracle账户

下载三个rpm包(对应oracle数据库的版本)

[root@localhost oracle]# ls

oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm  oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm

oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm

[root@localhost oracle]#

安装

[root@localhost oracle]#

[root@localhost oracle]# rpm -ivh oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm

Preparing...                ########################################### [100%]

  1:oracle-instantclient12.########################################### [100%]

[root@localhost oracle]# rpm -ivh oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm

Preparing...                ########################################### [100%]

  1:oracle-instantclient12.########################################### [100%]

[root@localhost oracle]# rpm -ivh oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm

Preparing...                ########################################### [100%]

  1:oracle-instantclient12.########################################### [100%]

设置环境变量

[root@localhost oracle]# export ORACLE_HOME=/usr/lib/oracle/12.1/client64

[root@localhost oracle]# export TNS_ADMIN=$ORACLE_HOME/network/admin

[root@localhost oracle]# export NLS_LANG='simplifiedchinese_china.UTF8'

[root@localhost oracle]# export LD_LIBRARY_PATH=$ORACLE_HOME/lib

[root@localhost oracle]# export PATH=$ORACLE_HOME/bin:$PATH

编译

[root@localhost oracle]# g++ -o test -I /usr/include/oracle/12.1/client64/ -L/usr/lib/oracle/12.1/client64/lib/ oracle_test.cpp -lclntsh -locci -lmql1 -lipc1 -lnnz12 -lons -lclntshcore -Wall -O -g

[root@localhost oracle]# ls

oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm  oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm  test

oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm  oracle_test.cpp

上一篇 下一篇

猜你喜欢

热点阅读