linux下连接oracle数据库_第1页
linux下连接oracle数据库_第2页
linux下连接oracle数据库_第3页
linux下连接oracle数据库_第4页
linux下连接oracle数据库_第5页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、源代码C+代码1. #i nclude 2. #in elude 3. #i nclude occi.h4. using n amespace oracle:occi;5. using n amespace std;6.6. int mai n()7. 8. stri ngusr=sys;9. stri ngpwd=orcl;10. stringSID=ORCL;/注意大小写11. stringdate;13.12. Environment *en v=E nviro nmen t:createE nvironmen t(E nvir onmen t:OBJECT);13. Conn ecti

2、 on *conn= en v-createC onn ecti on( usr,pwd,SID);/all stri ngs14. if(co nn)15. coutsuccess createC onnection !e ndl;16. else17. coutfailure createC onnection !createStateme nt();19. stri ng sSQL = select to_char(sysdate,yyyy-mm-dd hh24:mi:ss)from dual;20. stmt-setSQL(sSQL);25.26. ResultSet *rs = st

3、mt-executeQuery();27. if(rs- next()28. 29. date = rs-getStri ng(1);30. 31.31. cout now time :dateterm in ateC onnection(conn);33. Environmen t:term in ateE nvironmen t(e nv);36.34. return 0;35. 39.我 linux 上安装 oracle 路径:/u01/app/oracle/product/-L/u01/oracle/product/-L/u01/app/oracle/product编译命令:g+ -o

4、 conn -L/u01/app/oracle/product/ conn _db.cpp问题一:编译时报如下错误:Shell代码1. oraclelocalhost demo$ g+-o conn/ -L/u01/oracle/product/conn_db.cpp2. g+: g+: No such file or directory3. conn _db.cpp:3:18: error: occi.h: No such file or directory4. conn _db.cpp:4: error: oracle has not bee n declared5. conn _db.c

5、pp:4: error: occi is not a n amespace-n ame6. conn _db.cpp:4: error: expected n amespace-n ame before ; toke n7. conn _db.cpp: In function int main():8. conn _db.cpp:14: error: E nvironment was not declared in this scope9. conn _db.cpp:14: error: e nv was not declared in this scope10. conn_db.cpp:14

6、: error: Environment is not a class or namespace11. conn_db.cpp:14: error: Environment is not a class or namespace12. conn_db.cpp:15: error: Connection was not declared in this scope13. conn_db.cpp:15: error: conn was not declared in this scope14. conn_db.cpp:21: error: Statement was not declared in

7、 this scope15. conn_db.cpp:21: error: stmt was not declared in this scope16. conn_db.cpp:26: error: ResultSet was not declared in this scope17. conn_db.cpp:26: error: rs was not declared in this scope18. conn_db.cpp:35: error: Environment is not a class or namespace19.解决:编译时没有引入 OCCI库文件路径(oracle安装时候

8、这个库已经附带装好了)路径:/u01/app/oracle/product/编译命令增加 OCCI 库:g+ -o conn -I/u01/app/oracle/product/-L/opt/app/oracle/product/ -L/opt/oracle/product/conn _db.cpp问题2 :找不到对应函数Shell代码1. oraclelocalhost demo$ g+ -o conn -l/home/oracle/oracle/i nclude -L/opt/app/oracle/product/ -L/opt/oracle/product/ conn _db.cpp -

9、Wall -O -g2. /tmp/cclFs9xq.o: In fun cti on、ma in:3. /home/oracle/oracle/demo/c onn _db.cpp:14: un defi ned reference to oracle:occi:E nvir onmen t:createE nvironmen t(oracle:occi:E nvironment:Mode, void*, void* (*)(void*, un sig ned int), void* (*)(void*, void*, un sig ned in t), void (*)(void*, vo

10、id*)4. /home/oracle/oracle/demo/c onn _db.cpp:35: un defi ned reference to oracle:occi:E nvir onmen t:term in ateE nviro nmen t(oracle:occi:E nvironmen t*)5. collect2: ld retur ned 1 exit status6.解决:增加libocci.so 和libcIntsh.so(它们既为 OCCI库文件)指定编译修改后的编译命令:g+ -o conn -l/u01/app/oracle/product/-L/app/orac

11、le/product/ -L/u01/app/oracle/product/-lcl ntsh-locci conn _db.cpp另外可能在引入-Iclntsh -locci编译时可能会报找不到以下错误:Shell代码1. oraclelocalhost demo$g+ -o conn -l/u01/app/oracle/product/-L/app/oracle/product/-L/u01/app/oracle/product/-lcl ntsh-locci conn _db.cpp2. /usr/b in/ld: cannot find -lcl ntsh3. collect2: ld

12、 retur ned 1 exit status4. oraclelocalhost demo$5.解决:这是因为没有找到libelntsh.so 和libocci.so 链接库,将libclntsh.so和libocci. so拷贝到/usr/lib目录下就可以了补充:完成后改写环境变量:vi ./bash_profileport LD_LIBRARY_PATH-50RACLE_H0ME/lib:/usr/llb问题三:occi在linux编译运行时报libstdc+.so.6 冲突的问题Java代码1. oraclelocalhost demo$g+ -o conn -l/u01/app/

13、oracle/product/-L/app/oracle/product/-L/u01/app/oracle/product/-lcl ntsh -locci conn_db.cpp2. /usr/b in/ld: warning: libstdc+.so.5, n eeded by /opt/app/oracle/product/, may con flict with libstdc+.so.6解决:OCCI库在linux编译的时候,由于linux版本太高,会提示以上情况,实际上, 在大多数linux系统上,还保留有libstdc+5 的库,自己手工在编译的时候加上去就好了修改后的编译命令:g+ -o conn -l/u01/app/oracle/product/-L/app/oracle/prod uct/ -L/u01/app/oracle/product/-lclntsh -locci /usr/lib/libstdc+.so.5conn _db.cpp补充:编译之前将数据库监听开启在oracle的安装目录中找到lsnrctl执行文件,并运行它(监听开启)编译通过后执行结果输出:Shell代码1. oraclelocalhost demo$g+ -o conn -l/u01/app/oracle/produ

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论