Quantcast
Channel: MySQL Forums - Connector/C++
Viewing all articles
Browse latest Browse all 527

mysql connector 8.0.32 c++ can't get results don't understand (no replies)

$
0
0
This code is connecting. I was able to create tables without any problems. Now I want to run queries and get the results. Tried a lot, not sure of the documentation. I looked at the .h files and couldn't figure it out.

After I execute:
res = stmt->execute("select * from user"); //<<<this must be wrong.
while (res->next()) {

}

what are the exact steps from the stmt->execute //or something else,
to reading each tuple in the results?

Thanks

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

try
{
driver = get_driver_instance();
con = driver->connect(server, username, password);
}
catch (sql::SQLException e)
{
cout << "Could not connect to server. Error message: " << e.what() << endl;
system("pause");
exit(1);
}
cout << "connected to server" << endl;


stmt = con->createStatement();
stmt->execute("USE comp440");
stmt = con->createStatement();
res = stmt->execute("select * from user"); //<<<this must be wrong.
while (res->next()) {
// You can use either numeric offsets...
cout << "id = " << res->getInt(1); // getInt(1) returns the first column
// ... or column names for accessing results.
// The latter is recommended.
//cout << ", label = '" << res->getString("label") << "'" << endl;
}

Viewing all articles
Browse latest Browse all 527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>