resultset 读取并显示一行数据后,程序崩溃
程序只输出一行数据,但数据库中的数据不止一条。输出完成后,程序直接崩溃。
具体代码如下:
#include <iostream>
#include <occi.h>
using namespace std;
using namespace oracle::occi;
int main(){
Environment *env = NULL;
Connection *conn = NULL;
Statement *stmt = NULL;
try
{
env = Environment::createEnvironment(Environment::DEFAULT);
conn = env->createConnection("sa", "sa","XE"); //这句抛出异常,异常为24960
stmt = conn->createStatement();
stmt->setAutoCommit(true);
ResultSet *rs = stmt->executeQuery("Select * FROM student");
while (rs->next())
{
int num = rs->getInt(1);
string name = rs->getString(2);
cout << num << name <<endl;
}
}
catch(SQLException &ex)
{
cout << ex.getErrorCode() << ": " << ex.getMessage() << endl;
}
env->terminateConnection(conn);
conn->terminateStatement(stmt);
return 0;
}
------解决方案--------------------你的项目是debug版本,但链接了release版本的occi库