VC6 C/CPP操作ORACLE数据库 clilib方案


//VC6 ORACLE HA-Instant Client-v11.2.0.3.0-x86.rar  ocilib-4.2.0-windows.zip


#include "stdafx.h"
#include "ocilib.h"

#define OCI_CHARSET_ANSI

#ifdef _MSC_VER

#if defined(OCI_CHARSET_WIDE)
#pragma comment(lib, "ocilibw.lib")
#elif defined(OCI_CHARSET_ANSI)
#pragma comment(lib, "ociliba.lib")
#endif

#endif

#include <iostream>
#include <fstream>
#include <iomanip>
#include <sstream>

int test(void)
{
    OCI_Connection *cn;
OCI_Statement  *st;
    OCI_Resultset  *rs;
//要安装ORACLE Instant Client OCI_Initialize第二个参数可指令此目录
// char *home="D:\\Program Files\\Oracle\\Instant Client\\BIN";
    if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT | OCI_ENV_CONTEXT)){
printf("OCI_Initialize failure\n");
        return EXIT_FAILURE;
}
    cn = OCI_ConnectionCreate("192.168.1.7/ORCL", "user", "passwd", OCI_SESSION_DEFAULT);


    printf("Server major    version : %i\n",   OCI_GetServerMajorVersion(cn));
    printf("Server minor    version : %i\n",   OCI_GetServerMinorVersion(cn));
    printf("Server revision version : %i\n\n", OCI_GetServerRevisionVersion(cn));
    printf("Connection      version : %i\n\n", OCI_GetVersionConnection(cn));


 st  = OCI_StatementCreate(cn);

    OCI_ExecuteStmt(st, "select table_name from all_tables where owner='RX_DATASERVER'");
    rs = OCI_GetResultset(st);
    while (OCI_FetchNext(rs))
        printf("code: %i, name %s\n", OCI_GetInt(rs, 0)  , OCI_GetString(rs, 1));
    printf("\n%d row(s) fetched\n", OCI_GetRowCount(rs));

    OCI_Cleanup();
    return EXIT_SUCCESS;
}

int main(int argc, char* argv[])
{
printf("Hello World!\n");
test();
getchar();
return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值