check result from DB if value exists

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#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;
}


Thank you,

Merl
Last edited on
What are you doing? The manual states that getInt() returns an int
http://docs.oracle.com/cd/B28359_01/appdev.111/b28390/reference027.htm#LNCPP21531
Topic archived. No new replies allowed.