1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

Oracle ResultSet next fails

Discussion in 'General' started by russell01, Jul 21, 2011.

  1. russell01

    russell01 Guest

    The following statement inside loop fails:
    std::cout<<res->getString(1)<<std::endl;
    It displays only the first record and then the program crashes.
    Thanks

    Code (Text):
    #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("hr", "hr", "XE");

            stmt = con->createStatement("select first_name from employees");
            res = stmt->executeQuery();
           
            while (res->next())
                std::cout<<res->getString(1)<<std::endl;
           
            stmt->closeResultSet(res);
            con->terminateStatement(stmt);
            environment->terminateConnection(con);

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

     return 0;
    }
     
  2. zargon

    zargon Community Moderator Forum Guru

    Messages:
    2,351
    Likes Received:
    348
    Trophy Points:
    1,430
    Location:
    Aurora, CO
    It appears that res is not a pointer.