MySQL Forums
Forum List  »  Connector/C++

mysql connector 8.0.32 c++ can't get results don't understand
Posted by: Wayne Rasmussen
Date: April 22, 2023 09:09PM

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;
}

Options: ReplyQuote


Subject
Views
Written By
Posted
mysql connector 8.0.32 c++ can't get results don't understand
238
April 22, 2023 09:09PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.