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