Connector/c++ 查詢Mysql,出現 can't fetch because not on result set 錯誤

使用 Connector/C++ 查詢 Mysql 時,出現錯誤,提示以下:mysql

can't fetch because not on result set,

 

出現緣由能夠看這裏:http://stackoverflow.com/questions/17294611/sqlinvalidargumentexception-mysql-csql

 

意思就是,每次讀取 resultset裏面的內容前,你都須要 調用一次 next()fetch

像這樣:spa

        // 輸出結果    
        while(result->next())
        {
            int id = result->getInt("id");
            string name = result->getString("name");
            cout<<"testuser: "<< id <<" , "<<name<<endl;
        }                
相關文章
相關標籤/搜索