在C++代码中,可以很好地通过调用OTL类方法,实现客户端和oracle的交互。
下面是一个简单的开发步骤:
1、定义OTL_ORA9I等宏定义
3、初始化:otl_connect::otl_initialize();
4、使用otl_connect对象的server_attach、session_begin方法连接数据库
5、使用otl_stream或者otl_nocommit_stream方法执行sql语句。
声明对象:
otl_nocommit_stream osSeldb;
char *sql="select * from dual";
执行sql:osSeldb.open(50,
strSqldb.c_str(), db);
执行取数据、插入数据等操作。。。
关闭对象: osSeldb.close();
注意:otl_stream,默认情况下,语句执行完毕后,会自动提交数据库,需慎用。
开发举例:
#include
#include
#include
#define OTL_ORA9I // Compile OTL 4.0/OCI9i
#define OTL_ORA_UTF8 // Enable UTF8 OTL for OCI9i
#define OTL_STL
#define OTL_UNCAUGHT_EXCEPTION_ON
#define OTL_STL_NOSTD_NAMESPACE
#define OTL_ORA9I
#incl