oracle版本为oracle9i客户端精简版,编译C++工具为VC++6.0
代码如下:#include <iostream>
using namespace std;
#include <stdio.h>#define OTL_ORA9I // Compile OTL 4.0/OCI9i
#define OTL_UNICODE // Enable Unicode OTL for OCI9i
#include <otlv4.h> // include the OTL 4.0 header fileotl_connect db; // connect objectvoid insert()
// insert rows into table
{
otl_stream o(50, // buffer size
"insert into test_tab values(:f1<float>,:f2<char[31]>;)",
// SQL statement
db // connect object
);
char tmp[32];
unsigned short tmp2[32]; // Null terminated Unicode character array.for(int i=1;i<=100;++i){
#if defined(_MSC_VER)
#if (_MSC_VER >= 1400) // VC++ 8.0 or higher
sprintf_s(tmp,sizeof(tmp),"Name%d",i);
#else
sprintf(tmp,"Name%d",i);
#endif
#else
sprintf(tmp,"Name%d",i);
#endif
unsigned short* c2=tmp2;
char* c1=tmp;
// Unicode's first 128 characters are ASCII (0..127), so
// all is needed for converting ASCII into Unicode is as follows:
while(*c1){
*c2=OTL_SCAST(unsigned char,*c1);
++c1; ++c2;
}
*c2=0; // target Unicode string is null terminated,
// only the null terminator is a two-byte character,
// not one-byte
o<<static_cast<float>(i);
o<<reinterpret_cast<unsigned char*>(tmp2);
// overloaded operator<<(const unsigned char*) in the case of Unicode
// OTL accepts a pointer to a Unicode character array.
// operator<<(const unsigned short*) wasn't overloaded
// in order to avoid ambiguity in C++ type casting.
}}void select()
{
otl_stream i(50, // buffer size
"select * from test_tab where f1>=:f<int> and f1<=:f*2",
// SELECT statement
db // connect object
);
// create select streamfloat f1;
unsigned short f2[32];i<<8; // assigning :f = 8
// SELECT automatically executes when all input variables are
// assigned. First portion of output rows is fetched to the bufferwhile(!i.eof()){ // while not end-of-data
i>>f1;
i>>reinterpret_cast<unsigned char*>(f2);
// overloaded operator>>(unsigned char*) in the case of Unicode
// OTL accepts a pointer to a Unicode chracter array.
// operator>>(unsigned short*) wasn't overloaded
// in order to avoid ambiguity in C++ type casting.
cout<<"f1="<<f1<<", f2=";
// Unicode's first 128 characters are ASCII, so in order
// to convert Unicode back to ASCII all is needed is
// as follows:
for(int j=0;f2[j]!=0;++j){
cout<<static_cast<char>(f2[j]);
}
cout<<endl;
}i<<4; // assigning :f = 4
// SELECT automatically executes when all input variables are
// assigned. First portion of output rows is fetched to the bufferwhile(!i.eof()){ // while not end-of-data
i>>f1>>reinterpret_cast<unsigned char*>(f2);
cout<<"f1="<<f1<<", f2=";
for(int j=0;f2[j]!=0;++j){
cout<<static_cast<char>(f2[j]);
}
cout<<endl;
}}int main()
{
otl_connect::otl_initialize(); // initialize OCI environment
try{ db.rlogon("scott/tiger"); // connect to Oracle otl_cursor::direct_exec
(
db,
"drop table test_tab",
otl_exception::disabled // disable OTL exceptions
); // drop table otl_cursor::direct_exec
(
db,
"create table test_tab(f1 number, f2 varchar2(30))"
); // create table insert(); // insert records into table
select(); // select records from table}catch(otl_exception& p){ // intercept OTL exceptions
cerr<<p.msg<<endl; // print out error message
cerr<<p.stm_text<<endl; // print out SQL that caused the error
cerr<<p.var_info<<endl; // print out the variable that caused the error
}db.logoff(); // disconnect from Oraclereturn 0;}
编译后缺少头文件oci.h,我也知道我装的是精简版的oracle,问题是我装的是 win7系统,装了2次oracle9i的完整版客户端装不上,在实在没办法的情况下我只能把同事装过9i完整版下的oci目录(包括oci.h的include 和oci.lib的lib)拷贝到我的oracle目录里,并且vc编译器里设置好路径,在把otlv4.h放入vc的inlucde目录里,最后在编译不报缺少oci.h的错误了,但出现以下错误:
mytest1.obj : error LNK2001: unresolved external symbol _OCIHandleFree
mytest1.obj : error LNK2001: unresolved external symbol _OCIServerDetach
mytest1.obj : error LNK2001: unresolved external symbol _OCISessionEnd
mytest1.obj : error LNK2001: unresolved external symbol _OCIBindByName
mytest1.obj : error LNK2001: unresolved external symbol _OCIAttrGet
mytest1.obj : error LNK2001: unresolved external symbol _OCIStmtFetch
mytest1.obj : error LNK2001: unresolved external symbol _OCIInitialize
mytest1.obj : error LNK2001: unresolved external symbol _OCIAttrSet
mytest1.obj : error LNK2001: unresolved external symbol _OCIServerAttach
mytest1.obj : error LNK2001: unresolved external symbol _OCIHandleAlloc
mytest1.obj : error LNK2001: unresolved external symbol _OCIEnvInit
mytest1.obj : error LNK2001: unresolved external symbol _OCISessionBegin
mytest1.obj : error LNK2001: unresolved external symbol _OCIStmtExecute
mytest1.obj : error LNK2001: unresolved external symbol _OCIStmtPrepare
mytest1.obj : error LNK2001: unresolved external symbol _OCIDefineByPos
mytest1.obj : error LNK2001: unresolved external symbol _OCIParamGet
mytest1.obj : error LNK2001: unresolved external symbol _OCIErrorGet
mytest1.obj : error LNK2001: unresolved external symbol _OCIDescriptorFree
mytest1.obj : error LNK2001: unresolved external symbol _OCIDescriptorAlloc
mytest1.obj : error LNK2001: unresolved external symbol _OCITransCommit
mytest1.obj : error LNK2001: unresolved external symbol _OCILobWrite请大哥们帮帮小弟,怎么解决?谢谢了
代码如下:#include <iostream>
using namespace std;
#include <stdio.h>#define OTL_ORA9I // Compile OTL 4.0/OCI9i
#define OTL_UNICODE // Enable Unicode OTL for OCI9i
#include <otlv4.h> // include the OTL 4.0 header fileotl_connect db; // connect objectvoid insert()
// insert rows into table
{
otl_stream o(50, // buffer size
"insert into test_tab values(:f1<float>,:f2<char[31]>;)",
// SQL statement
db // connect object
);
char tmp[32];
unsigned short tmp2[32]; // Null terminated Unicode character array.for(int i=1;i<=100;++i){
#if defined(_MSC_VER)
#if (_MSC_VER >= 1400) // VC++ 8.0 or higher
sprintf_s(tmp,sizeof(tmp),"Name%d",i);
#else
sprintf(tmp,"Name%d",i);
#endif
#else
sprintf(tmp,"Name%d",i);
#endif
unsigned short* c2=tmp2;
char* c1=tmp;
// Unicode's first 128 characters are ASCII (0..127), so
// all is needed for converting ASCII into Unicode is as follows:
while(*c1){
*c2=OTL_SCAST(unsigned char,*c1);
++c1; ++c2;
}
*c2=0; // target Unicode string is null terminated,
// only the null terminator is a two-byte character,
// not one-byte
o<<static_cast<float>(i);
o<<reinterpret_cast<unsigned char*>(tmp2);
// overloaded operator<<(const unsigned char*) in the case of Unicode
// OTL accepts a pointer to a Unicode character array.
// operator<<(const unsigned short*) wasn't overloaded
// in order to avoid ambiguity in C++ type casting.
}}void select()
{
otl_stream i(50, // buffer size
"select * from test_tab where f1>=:f<int> and f1<=:f*2",
// SELECT statement
db // connect object
);
// create select streamfloat f1;
unsigned short f2[32];i<<8; // assigning :f = 8
// SELECT automatically executes when all input variables are
// assigned. First portion of output rows is fetched to the bufferwhile(!i.eof()){ // while not end-of-data
i>>f1;
i>>reinterpret_cast<unsigned char*>(f2);
// overloaded operator>>(unsigned char*) in the case of Unicode
// OTL accepts a pointer to a Unicode chracter array.
// operator>>(unsigned short*) wasn't overloaded
// in order to avoid ambiguity in C++ type casting.
cout<<"f1="<<f1<<", f2=";
// Unicode's first 128 characters are ASCII, so in order
// to convert Unicode back to ASCII all is needed is
// as follows:
for(int j=0;f2[j]!=0;++j){
cout<<static_cast<char>(f2[j]);
}
cout<<endl;
}i<<4; // assigning :f = 4
// SELECT automatically executes when all input variables are
// assigned. First portion of output rows is fetched to the bufferwhile(!i.eof()){ // while not end-of-data
i>>f1>>reinterpret_cast<unsigned char*>(f2);
cout<<"f1="<<f1<<", f2=";
for(int j=0;f2[j]!=0;++j){
cout<<static_cast<char>(f2[j]);
}
cout<<endl;
}}int main()
{
otl_connect::otl_initialize(); // initialize OCI environment
try{ db.rlogon("scott/tiger"); // connect to Oracle otl_cursor::direct_exec
(
db,
"drop table test_tab",
otl_exception::disabled // disable OTL exceptions
); // drop table otl_cursor::direct_exec
(
db,
"create table test_tab(f1 number, f2 varchar2(30))"
); // create table insert(); // insert records into table
select(); // select records from table}catch(otl_exception& p){ // intercept OTL exceptions
cerr<<p.msg<<endl; // print out error message
cerr<<p.stm_text<<endl; // print out SQL that caused the error
cerr<<p.var_info<<endl; // print out the variable that caused the error
}db.logoff(); // disconnect from Oraclereturn 0;}
编译后缺少头文件oci.h,我也知道我装的是精简版的oracle,问题是我装的是 win7系统,装了2次oracle9i的完整版客户端装不上,在实在没办法的情况下我只能把同事装过9i完整版下的oci目录(包括oci.h的include 和oci.lib的lib)拷贝到我的oracle目录里,并且vc编译器里设置好路径,在把otlv4.h放入vc的inlucde目录里,最后在编译不报缺少oci.h的错误了,但出现以下错误:
mytest1.obj : error LNK2001: unresolved external symbol _OCIHandleFree
mytest1.obj : error LNK2001: unresolved external symbol _OCIServerDetach
mytest1.obj : error LNK2001: unresolved external symbol _OCISessionEnd
mytest1.obj : error LNK2001: unresolved external symbol _OCIBindByName
mytest1.obj : error LNK2001: unresolved external symbol _OCIAttrGet
mytest1.obj : error LNK2001: unresolved external symbol _OCIStmtFetch
mytest1.obj : error LNK2001: unresolved external symbol _OCIInitialize
mytest1.obj : error LNK2001: unresolved external symbol _OCIAttrSet
mytest1.obj : error LNK2001: unresolved external symbol _OCIServerAttach
mytest1.obj : error LNK2001: unresolved external symbol _OCIHandleAlloc
mytest1.obj : error LNK2001: unresolved external symbol _OCIEnvInit
mytest1.obj : error LNK2001: unresolved external symbol _OCISessionBegin
mytest1.obj : error LNK2001: unresolved external symbol _OCIStmtExecute
mytest1.obj : error LNK2001: unresolved external symbol _OCIStmtPrepare
mytest1.obj : error LNK2001: unresolved external symbol _OCIDefineByPos
mytest1.obj : error LNK2001: unresolved external symbol _OCIParamGet
mytest1.obj : error LNK2001: unresolved external symbol _OCIErrorGet
mytest1.obj : error LNK2001: unresolved external symbol _OCIDescriptorFree
mytest1.obj : error LNK2001: unresolved external symbol _OCIDescriptorAlloc
mytest1.obj : error LNK2001: unresolved external symbol _OCITransCommit
mytest1.obj : error LNK2001: unresolved external symbol _OCILobWrite请大哥们帮帮小弟,怎么解决?谢谢了
解决方案 »
- listbox中的滚动条如何重绘?
- EditBox控件的问题,可能不太常用,请高手指教
- 802.1X认证+dhcp
- Some useful tips about developing multi-threading applications
- vc编的dll在vb中怎么用 !和vb工程调用vb的dll一样吗? 急!!!!!!!!!!!!!!!!!!!!!!!???
- ★★★★★ 双星^_^散分 ★★★★★
- 请问在listctrl中最多可以放多少item啊?
- MyGod,非常事情.
- 怎么能够拿到tcp或者ip包?
- ICQ 如何设置为不随电脑启动而启动?
- 如何使用OPENSSL中的AES算法加密文件。
- 麻烦高手给写个VC高用DELPHI DLL的程序
给 或多或少有帮助
你实际上的配置的问题:
1、project->setting->Link object/library modules中,在最后处加上oci.lib
2、tools->option->Directories
show directories for
选择"Include files"时,请在其下方Directories中添加otl头文件及oracle之oci库路径所在目录所在的目录,类似如下:
D:\Programs\Oracle10gEn\OCI\include
E:\Work\otl
选择"Library files"时,添加OCI.lib的路径,类似如下:
D:\Programs\Oracle10gEn\OCI\lib\MSVC
D:\Programs\Oracle10gEn\OCI\lib\MSVC\vc7
D:\Programs\Oracle10gEn\OCI\lib\MSVC\vc71你的问题是没有加oci.lib的缘故。
#include <iostream>
using namespace std;#include <stdio.h>#define OTL_ORA10G
#include <otlv4.h> // include the OTL 4.0 header fileotl_connect db; // connect objectvoid insert()
// insert rows into table
{
otl_stream o(50,
"insert into test_tab values(:f1<float>,:f2<char[31]>)",
db
);
char tmp[32];
for(int i=1;i<=100;++i){
sprintf(tmp,"Name%d",i);
o<<(float)i<<tmp;
}
}void select()
{
otl_stream i(50,
"select * from test_tab where f1>=:f<int> and f1<=:f*2",
db
);
// create select stream
float f1;
char f2[31];
i<<4;
while(!i.eof()){ // while not end-of-data
i>>f1>>f2;
cout<<"f1="<<f1<<", f2="<<f2<<endl;
}
}int main()
{
otl_connect::otl_initialize(); // initialize OCI environment
try
{
db.rlogon("system/scott"); // connect to Oracle
otl_cursor::direct_exec
(
db,
"drop table test_tab",
otl_exception::disabled // disable OTL exceptions
); // drop table
otl_cursor::direct_exec
(
db,
"create table test_tab(f1 number, f2 varchar2(30))"
); // create table
insert(); // insert records into table
db.logoff(); // disconnect from Oracle
db.server_attach(); // attach to the local Oracle server
// In order to connect to a remote server,
// a TNS alias needs to be specified
for(int i=1;i<=100;++i)
{
cout<<"Session begin ==> "<<i<<endl;
db.session_begin("scott","tiger");
select(); // select records from table
cout<<"Session end ==> "<<i<<endl;
db.session_end(); // end session
}
db.server_detach(); // detach from the Oracle server
}
catch(otl_exception& p){ // intercept OTL exceptions
cerr<<p.msg<<endl; // print out error message
cerr<<p.stm_text<<endl; // print out SQL that caused the error
cerr<<p.var_info<<endl; // print out the variable that caused the error
}
db.logoff(); // make sure that the program gets disconnected from Oracle
return 0;
}