The API for fetching result sets is identical for (simple)
statments and prepared statements. If your query returns one
result set you should use
sql::Statement::executeQuery()
or
sql::PreparedStatement::executeQuery()
to run your query. Both methods return
sql::ResultSet
objects. The preview
version does buffer all result sets on the client to support
cursors.
// ... sql::Connection *con; sql::Statement *stmt sql::ResultSet *res; // ... stmt = con->createStatement(); // ... res = stmt->executeQuery("SELECT id, label FROM test ORDER BY id ASC"); while (res->next()) { // You can use either numeric offsets... cout << "id = " <&;t; res->getInt(0); // ... or column names for accessing results. » The latter is recommended. cout << ", label = '" << » res->getString("label") << "'" << endl; } delete res; delete stmt; delete con;
Note that you have to free
sql::Statement
,
sql::Connection
and
sql::ResultSet
objects explicitly using
delete.
The usage of cursors is demonstrated in the examples contained in the download package.
User Comments
Add your own comment.