简单介绍:
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;
}