您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

OTL的使用

2026/2/21 19:33:50发布26次查看
otl可通过odbc,数据库本身的连接库如oci,与数据库进行交互,跨平台,跨数据库,api使用方便且仅只是个头文件,我一直都使用这个。 otl的官网是:http://otl.sourceforge.net/ 里面例子文档什么的都相当全。 以otl连接oracle 11g为例,说明下在vs中的使用方式:
otl可通过odbc,数据库本身的连接库如oci,与数据库进行交互,跨平台,跨数据库,api使用方便且仅只是个头文件,我一直都使用这个。
otl的官网是:http://otl.sourceforge.net/ 里面例子文档什么的都相当全。
以otl连接oracle 11g为例,说明下在vs中的使用方式:
1. vs 编译环境设置
a. 在工程项目中引入otlv4.h头文件
b. 在vs中指定头文件目录:
c:\oracle\product\11.2.0\dbhome_1\oci\include
c.指定 附加库目录:
c:\oracle\product\11.2.0\dbhome_1\oci\lib\msvc
d. 输入附加库:
oci.lib
2. 以普通用户连接oracle数据库的例子:
#include #include #define otl_ora11g_r2 // compile otl 4.0/oci11.2#define otl_ora_utf8#include otlv4.h // include the otl 4 header file//#pragma comment(lib,oci.lib)using namespace std;otl_connect oracledb; int main(void){ //int otlsession_mode = oci_sysdba; try{ otl_connect::otl_initialize(); oracledb.rlogon(system/xcldb@xcldb); //....... }catch(otl_exception &p) { cerr< 编译注意事项:a. 如果使用的oracle oci是64位的,vs就要编译成64位的程序,如果编译成32位,会提示找不到oracle的动态库。
b.因为oracle连接数据库较慢,有些会使用多线程,这时要注意线程安全问题.
通过otl_initialize()函数设不同的参数来解决.
// threaded_mode = 1 means the multi-threaded mode, 0 -- the single threaded mode
otl_connect::otl_initialize(0);
3. 用sysdba登录身份连接oracle数据库
当sys用户连接oracle时,如果用普通用户会报ora-28009 应当以sysdba或sysoper建立sys连接错误.
在session_begin中指定用户登录身份即可:
db.session_begin(m_struser.c_str(),m_strpassword.c_str(),0,oci_sysdba);
oci_default
oci_sysdba -- in this mode, the user is authenticated for sysdba access.
oci_sysoper -- in this mode, the user is authenticated for sysoper access.
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product