Linux c++ 连接Oracle
1.在已经安装Oracle的linux系统上安装
instantclient-basic-linux.x64-11.2.0.3.0.zip
2.unzipit,copylibocci.soandlibclntsh.soto/libor/usr/lib
3.runldconfig
4.
#include <iostream> #include <string> #include "occi.h" using namespace oracle::occi; using namespace std; int main() { string usr="test"; string pwd="t2npRh6Oq5su5dBnS4VrpHIYLKv+"; string SID="test"; string date; Environment *env=Environment::createEnvironment(Environment::OBJECT); Connection *conn= env->createConnection(usr,pwd,SID);//all strings if(conn) cout<<"success createConnection!"<<endl; else cout<<"failure createConnection!"<<endl; Statement *stmt = conn->createStatement(); string sSQL = "select to_char(enddate,'yyyy-mm-dd hh24:mi:ss') from info"; stmt->setSQL(sSQL); ResultSet *rs = stmt->executeQuery(); if(rs->next()) { date = rs->getString(1); } cout<<"now time :"<<date<<endl; env->terminateConnection(conn); Environment::terminateEnvironment(env); return 0; }
compile
g++ main.cpp -o test -I/u01/app/oracle/product/11.2.0/dbhome_1/rdbms/public/ -L/u01/app/oracle/product/11.2.0/dbhome_1/rdbms/lib
Makefile
INCDIR=-I$(ORACLE_HOME)/rdbms/public/ LDFLAGS=-L$(ORACLE_HOME)/rdbms/lib/ -lclntsh -locci COMPILECMD=g++ targets := clean .PHONY: all clean all:clean @echo "run make all " $(COMPILECMD) main.cpp -o test $(INCDIR) $(LDFLAGS) clean: @echo "run make clean " rm -rf test
相关推荐
iilegend 2020-10-19
Hody 2020-08-16
ihuaqiang 2020-08-16
Carlos 2020-07-29
wpfeitian 2020-07-26
Justdoit00 2020-06-26
dataminer 2020-06-25
昊 2020-06-16
lklong 2020-11-22
oraclemch 2020-11-06
shilukun 2020-10-10
周嘉笙 2020-11-09
EricRay 2020-10-16
zhuzhufxz 2020-09-16
dataminer 2020-08-17
bfcady 2020-08-16
FightFourEggs 2020-08-16
数据库设计 2020-08-16