问题现象:
表数据
控制台的输出:
问题描述: 编译正常通过,也能成功连接上数据库,成功从数据库中查询数据到occi结果集,从结果集中用getInt取整型字段的数据能成功,但是当字段是char型时用getString获取时报错
环境:
系统:window 7
集成环境:vs2017
数据库:oracle_11gR2
问题代码:
#include <iostream>
#define WIN32COMMON
#include <occi.h>
using namespace std;
using namespace oracle::occi;
int main()
{
system("pause");
Environment *env = Environment::createEnvironment();
if (NULL == env) {
cout << "createEnvironment error." << endl;
return -1;
}
else
cout << "success" << endl;
string name = "scott";
string pass = "tiger";
string srvName = "localhost:1521/orcl";
try
{
Connection *conn = env->createConnection(name, pass, srvName);
if (NULL == conn) {
cout << "createConnection error." << endl;
return -1;
}
else
cout << "conn success" << endl;
Statement *pStmt = NULL;
pStmt = conn->createStatement();
if (NULL == pStmt) {
cout << "createStatement error." << endl;
return -1;
}
std::string strTemp;
ResultSet *pRs = pStmt->executeQuery("select * from ACTICLEDOCUMENT");
while (pRs->next()) {
cout<< pRs->getInt(1)<<endl;
cout<< pRs->getString(2);
}
pStmt->closeResultSet(pRs);
conn->terminateStatement(pStmt);
env->terminateConnection(conn);
}
catch (SQLException e)
{
cout << e.what() << endl;
system("pause");
return -1;
}
Environment::terminateEnvironment(env);
cout << "end!" << endl;
system("pause");
return 0;
}
待解决!!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)