rajdey1 0 Newbie Poster

Hi
I am writing a program that will read the number of aborted_connects from the global variable...

Below is the program code....

I am facing difficulty in displaying the result set

#include "stdafx.h"
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/resultset.h>
#include <cppconn/exception.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>
#include <iostream>
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{cout << endl;

try {
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
sql::PreparedStatement *pstmt;

/* Create a connection */
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
/* this line prepares the query*/
pstmt = con->prepareStatement("Show global status like 'aborted_connects'");

/*this executes */
res = pstmt->executeQuery();


/*this line is suposed to print the number of aborted_connects */
/*this is the line where i am facing problem */
cout << "\t... MySQL counts: " << res->getInt(2) << endl;
delete res;
delete pstmt;
delete con;
} catch (sql::SQLException &e) {
cout << "# ERR: SQLException in " << __FILE__;
cout << "(" << __FUNCTION__ << ") on line "
<< __LINE__ << endl;
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() <<
" )" << endl;
}
cout << endl;

return EXIT_SUCCESS;
}

Please read carefully i am facing difficulty in printing the number of aborted_connects from result set
I am getting the following error on execution of the above code

# ERR: SQLException in .\sqltestintru.cpp(wmain) online 52

# ERR: mySQL_Prepared_ResultSet::getInt: can't fetch becuse not on result set (MySQL error code: 0,SQLState: )

Please help me to rectify the error ..

Thanks in Advance

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.