Oracle数据库开发——使用OCILIB

简单介绍:

OCILIB:C Driver for Oracle

Open source c driver for accessing Oracle databases

OCILIB库有如下特征:

(1)提供了丰富、完成的特定,可以很方便使用的API接口

(2)可以在所有Oracle平台上运行

(3)代码由纯ISO C编写,提供了对 ISO C Unicode的支持

(4)保证了搞效率

(5)封装了OCI(即 Oracle Call Interface)

(信息来自于主页:http://orclib.sourceforge.net/

使用方法:

以Windows平台为例:

  • unzip the archive
  • copy ocilib\include\ocilib.h to any place located in your include’s path
  • copy ocilib\lib32|64\ocilib[x].lib to any place located in your libraries path
  • copy ocilib\lib32|64\ocilib[x].dll to any place located in your windows path

实验:

如:在VC6.0下建立 Win32 Cosole Application 工程,需要进行如下配置:

(1)



(2)



代码:

#include "ocilib.h" //包含头文件
int main(void)
{
OCI_Connection *cn;
if(!OCI_Initialize(NULL,NULL,OCI_ENV_DEFAULT)) //必须要初始化库
return EXIT_FAILURE;
cn = OCI_ConnectionCreate("myDB", "sys", "xbp1989", OCI_SESSION_SYSDBA);
if( cn!=NULL )
{
printf(OCI_GetVersionServer(cn));
printf("Server major version: %i\n", OCI_GetServerMajorVersion(cn));
printf("Server minor version: %i\n", OCI_GetServerMinorVersion(cn));
printf("Server  revision version: %i\n", OCI_GetServerRevisionVersion(cn));
printf("Connection version: %i\n", OCI_GetVersionConnection(cn));

OCI_Statement *st;
OCI_Resultset *rs;
st = OCI_StatementCreate(cn);
OCI_ExecuteStmt(st, "select * from student");
rs = OCI_GetResultset(st);
while(OCI_FetchNext(rs))
printf("学号: %i, 姓名: %s\n", OCI_GetInt(rs,1), OCI_GetString(rs,2));
printf("\n%d row(s) fetched\n", OCI_GetRowCount(rs));
OCI_StatementFree(st);
OCI_ConnectionFree(cn);
}
OCI_Cleanup();
return EXIT_SUCCESS;
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值