本文介绍了C ++检查db的结果值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,



我有一个很大的问题,如果它包含某个值并打印出来,我必须检查数据库中的结果集。但它不能像我尝试的那样工作。我可以打印结果,但我不知道如何将它保存在数组中,如果可能的话。



有没有人知道它是如何工作的?





这是我的尝试:



size_t myArraySize = sizeof( res-> getInt(1))/ sizeof(int);

int * end = res-> getInt(1)+ myArraySize;

//找到值3:

int * result = std :: find(res-> getInt(1),end,3);

if(result!= end){

cout<< 找到;

}





但它不起作用。





#include< iostream>

#include< occi.h>



使用命名空间std;



int main(){



oracle :: occi ::环境*环境;

oracle :: occi :: Connection * con;

oracle :: occi :: Statement * stmt;

oracle :: occi :: ResultSet * res;



尝试{



environment = oracle :: occi :: Environment :: createEnvironment(oracle :: occi :: Environment :: DEFAULT);

con = environment-> createConnection(user,pw,DB);



string asd =从表中选择id;

stmt = con> createStatement(asd);

res = stmt-> executeQuery();



while(res-> next())

// std :: cout<< res-> getInt(1)<<<& lt; res-> getString(2)<< std :: endl;

std :: cout<< res-> getInt(1)<<,;



size_t myArraySize = sizeof(res-> getInt(1))/ sizeof(int);

int * end = res- > getInt(1)+ myArraySize;

//找到值3:

int * result = std :: find(res-> getInt(1),结束,3);

if(结果!=结束){

cout<< 找到;

}



stmt-> closeResultSet(res);

con> terminateStatement(stmt);

environment-> terminateConnection(con);



} catch(oracle :: occi :: SQLException& e){

std :: cout<< e.what();

}



返回0;

}

编辑&运行





谢谢,



Merl

Hey guys,

I have a big problem, I have to check a result set i get from a database if it contains a certain value and print something. But it does not work the way I tried it. I can print the result, but I dont know how to save it in an array, if that is even possible.

Does anyone have an idea how it could work?


This was my try:

size_t myArraySize = sizeof(res->getInt(1)) / sizeof(int);
int *end = res->getInt(1) + myArraySize;
// find the value 3:
int *result = std::find(res->getInt(1), end, 3);
if (result != end) {
cout << "found";
}


but it does not work.


#include <iostream>
#include <occi.h>

using namespace std;

int main(){

oracle::occi::Environment* environment;
oracle::occi::Connection *con;
oracle::occi::Statement* stmt;
oracle::occi::ResultSet* res;

try{

environment = oracle::occi::Environment::createEnvironment(oracle::occi::Environment::DEFAULT);
con = environment->createConnection("user", "pw", "DB");

string asd = "select id from table";
stmt = con->createStatement(asd);
res = stmt->executeQuery();

while (res->next())
//std::cout<<res->getInt(1)<<" "<<res->getString(2)<<std::endl;
std::cout<<res->getInt(1)<<",";

size_t myArraySize = sizeof(res->getInt(1)) / sizeof(int);
int *end = res->getInt(1) + myArraySize;
// find the value 3:
int *result = std::find(res->getInt(1), end, 3);
if (result != end) {
cout << "found";
}

stmt->closeResultSet(res);
con->terminateStatement(stmt);
environment->terminateConnection(con);

}catch(oracle::occi::SQLException &e){
std::cout<<e.what();
}

return 0;
}
Edit & Run


Thank you,

Merl

推荐答案


这篇关于C ++检查db的结果值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 00:45